When writing out a flat pattern as DXF or DWG you have control over which layers various bits of the flat pattern are written to. You can see these options in the Save Copy As dialog when you right-click on the flat pattern in the browser, as shown below.
The dialog allows you to specify the layer name for various categories of items that can exist in a flat pattern. You can change the layer names and control which groups are written to the DXF or DWG file. This is all good functionality but you’re limited to the predefined sets of groups. There is a solution to this that allows you to have very detailed control over which layer specific entities are written to.
Using the API you can assign an attribute to an edge in the flat pattern and this will control which layer that edge will be written to in the DXF or DWG file. The name of the layer is specified by the attribute. Below is a very simple example that will add an attribute to a selected edge.
' This program assumes that a sheet metal document is open, the
' flat pattern is active, and that an edge of the flat pattern is
' selected. For simplicity, no error checking is done to
' validate this.
Sub AddLayerName()
' Get the active document.
Dim oDoc As PartDocument
Set oDoc = ThisApplication.ActiveDocument
' Get the selected edge.
Dim oEdge As Edge
Set oEdge = oDoc.SelectSet(1)
' Add an attribute set named “FlatPatternAttributes”
' to the selected edge.
Dim attSet As AttributeSet
Set attSet = oEdge.AttributeSets.Add("FlatPatternAttributes")
' Add an attribute specifying the name of the layer.
Dim myLayerName As String
myLayerName = "CustomLayer"
Call attSet.Add("LayerName", kStringType, myLayerName)
End Sub
Any edge on the flat pattern model is valid to name. The bend and tangent lines are also Edge objects and can be assigned a layer name too. Defining layers for sketches and sketch entities is not currently supported so attributes added to these will be ignored. When you specify the layer of an entity using this technique it overrides the dialog settings. For example, if an edge will normally be written to the IV_OUTER_PROFILE it will instead be written to the layer you specify using the attribute.
One other thing to be aware of is that only the edges that are visible are written to the DXF or DWG file. The picture below shows a flat pattern as viewed with the Z axis pointed towards you. This is the geometry you would expect in the output DXF or DWG file.
Here’s a close-up of an area of the model where it’s slightly rotated. The red selected edge is on the “back” of the part and will not be written out to the DXF or DWG file. Adding an attribute to this edge won’t have any effect since the edge is not written out. The same is true for the bend and tangent lines too. Only those on the “front” of the part will be written out.
When edges have been attributed in this way the Save Copy As command honors this by displaying this as a layer in the dialog to allow you to choose whether to write it out or not. Notice in the picture below that the last layer in the list is “CustomLayer” which is the name that was assigned using the macro above.
These layer overrides are also honored when using the API to write out a DXF or DWG file of the flat pattern. The program below is directly from Inventor’s online help and illustrates using the API to write out a DXF file of the flat pattern. See the topic on the DataIO object in the online help for additional information about this.
Public Sub WriteSheetMetalDXF()
' Get the active document. This assumes it is a part document.
Dim oDoc As PartDocument
Set oDoc = ThisApplication.ActiveDocument
' Get the DataIO object.
Dim oDataIO As DataIO
Set oDataIO = oDoc.ComponentDefinition.DataIO
' Build the string that defines the format of the DXF file.
Dim sOut As String
sOut = "FLAT PATTERN DXF?AcadVersion=R12"
' Create the DXF file.
oDataIO.WriteDataToFile sOut, "C:\temp\flat.dxf"
End Sub
If attributes are something new to you watch this blog over the next couple of weeks for additional postings explaining attributes in more detail.