I need to take a dxf file (actually about 30) with 10 to 20 layers and make one file per layer. Any thoughts on how to use VBA in Intellicad to do this?
I'm new to Intellicad (but have some Intergraph, DXF, and VB experience). I see from previously posted examples in the VBA forum how to use VBA to:
- open a drawing,
- loop thru the layer definitions and
- save the doument to a file,
but nothing on how to loop thru the list of entities and copy them to a new drawing if they are on a certain layer. Should I use the block collection? (are all entities in a block? or are block optional?)
Any help would be appreciated.
Brent Fraser
#2
Brent,
Thank you for posting this on the Forum as I requested (Brent sent me an email and I asked him to post and I would help him on the forum).
Have I got this right - You want to :
1/ Loop through each Layer
2/ Create a new drawing for each layer
3/ Create a selection of all the drawing entities on each layer.
4/ Move or Copy these entities into each of the drawings.
5/ Save the drawing as a *.dxf to create the new files you require.
What would you prefer to do, Move or Copy?
Have a look at at my VBA http://www.intellicadms.com/ubb/Forum3/HTML/000011.html This is based on Selection Sets with filters. In Intellicad you can create a Selection Set using the dxf filters. We know that the dxf code for layer is (8 . "Layer") so we can filter our selection based on this.
There is no need to use the block collection. These are required for different reasons and all you need is to filter a selection set using ' set the filter options
DXFNumber(0) = 8
DXFName(0) = "Layer.Name"
for item 3/ above.
Let me know how you get on.
------------------
Regards
John Finlay
Thank you for posting this on the Forum as I requested (Brent sent me an email and I asked him to post and I would help him on the forum).
Have I got this right - You want to :
1/ Loop through each Layer
2/ Create a new drawing for each layer
3/ Create a selection of all the drawing entities on each layer.
4/ Move or Copy these entities into each of the drawings.
5/ Save the drawing as a *.dxf to create the new files you require.
What would you prefer to do, Move or Copy?
Have a look at at my VBA http://www.intellicadms.com/ubb/Forum3/HTML/000011.html This is based on Selection Sets with filters. In Intellicad you can create a Selection Set using the dxf filters. We know that the dxf code for layer is (8 . "Layer") so we can filter our selection based on this.
There is no need to use the block collection. These are required for different reasons and all you need is to filter a selection set using ' set the filter options
DXFNumber(0) = 8
DXFName(0) = "Layer.Name"
for item 3/ above.
Let me know how you get on.
------------------
Regards
John Finlay
#3
Brent,
In the Document Object there is just the Method for your request.
Its called the Export Method and it has the following arguments:
1/ FileName
2/ Extension
3/ SelectionSet (optional)
The Export method will create a dxf file of a selection set.
Code Starts Here...........................
Sub EntityOnLayer()
Dim ssLayer As SelectionSet
Dim myLayer As Layer
Dim strLayerName As String
IntelliCAD.ActiveDocument.Activate
'Loop Through each Layer in the drawing
For Each myLayer In ActiveDocument.Layers
' Create a Filtered Selection Set using Private Function ssEntitiesOnLayer Below
Set ssLayer = ssEntitiesOnLayer(myLayer.Name)
' Highlight Entities in Selection set (This gives us something to look at)
ssLayer.Highlight True
' Export the Selectionset to a DXF File using the Drawing's Name
IntelliCAD.ActiveDocument.Export myLayer.Name, "dxf", ssLayer
Next ' Layer
End Sub
Private Function ssEntitiesOnLayer(strLayer As String) As SelectionSet
Dim objSS1 As SelectionSet
Dim DXFNumber(0) As Integer 'DXF Group Code Number
Dim DXFName(0) As Variant 'DXF Group Name
' if the SSName exists then clear it
Dim strSSName As String
strSSName = "SSName"
For Each objSS1 In IntelliCAD.ActiveDocument.SelectionSets
If objSS1.Name = strSSName Then objSS1.Clear
Next
'Make empty selection Set
Set objSS1 = IntelliCAD.ActiveDocument.SelectionSets.Add(strSSName)
' set filters
DXFNumber(0) = 8
DXFName(0) = strLayer
' Populate the Selection set
objSS1.Select vicSelectionSetAll, , , DXFNumber, DXFName
' Set the Function's Object
Set ssEntitiesOnLayer = objSS1
End Function
Code Ends Here............................
You can add the usual error stuff.
Explanation of code:
The Subroutine EntityOnLayer loops through the Layers in the drawing and calls the Function ssEntitiesOnLayer which returns a selection set of the entities on the Layer.
The Subroutine highlights these entities and uses the Export Method to create a dxf file using the Layer's Name as the Filename.
What looked like a multi-staged task became quite simple using the Export Method.
------------------
Regards
John Finlay
In the Document Object there is just the Method for your request.
Its called the Export Method and it has the following arguments:
1/ FileName
2/ Extension
3/ SelectionSet (optional)
The Export method will create a dxf file of a selection set.
Code Starts Here...........................
Sub EntityOnLayer()
Dim ssLayer As SelectionSet
Dim myLayer As Layer
Dim strLayerName As String
IntelliCAD.ActiveDocument.Activate
'Loop Through each Layer in the drawing
For Each myLayer In ActiveDocument.Layers
' Create a Filtered Selection Set using Private Function ssEntitiesOnLayer Below
Set ssLayer = ssEntitiesOnLayer(myLayer.Name)
' Highlight Entities in Selection set (This gives us something to look at)
ssLayer.Highlight True
' Export the Selectionset to a DXF File using the Drawing's Name
IntelliCAD.ActiveDocument.Export myLayer.Name, "dxf", ssLayer
Next ' Layer
End Sub
Private Function ssEntitiesOnLayer(strLayer As String) As SelectionSet
Dim objSS1 As SelectionSet
Dim DXFNumber(0) As Integer 'DXF Group Code Number
Dim DXFName(0) As Variant 'DXF Group Name
' if the SSName exists then clear it
Dim strSSName As String
strSSName = "SSName"
For Each objSS1 In IntelliCAD.ActiveDocument.SelectionSets
If objSS1.Name = strSSName Then objSS1.Clear
Next
'Make empty selection Set
Set objSS1 = IntelliCAD.ActiveDocument.SelectionSets.Add(strSSName)
' set filters
DXFNumber(0) = 8
DXFName(0) = strLayer
' Populate the Selection set
objSS1.Select vicSelectionSetAll, , , DXFNumber, DXFName
' Set the Function's Object
Set ssEntitiesOnLayer = objSS1
End Function
Code Ends Here............................
You can add the usual error stuff.
Explanation of code:
The Subroutine EntityOnLayer loops through the Layers in the drawing and calls the Function ssEntitiesOnLayer which returns a selection set of the entities on the Layer.
The Subroutine highlights these entities and uses the Export Method to create a dxf file using the Layer's Name as the Filename.
What looked like a multi-staged task became quite simple using the Export Method.
------------------
Regards
John Finlay