Export Flat Patterns of Assembly as DXFs using Export Face As

Export Flat Patterns of Assembly as DXFs using Export Face As

cameron.houston
Enthusiast Enthusiast
1,219 Views
4 Replies
Message 1 of 5

Export Flat Patterns of Assembly as DXFs using Export Face As

cameron.houston
Enthusiast
Enthusiast

Hi All,

 

We currently have an illogic rule that for a given assembly, opens up the individual parts and checks if they have a flat pattern, if they do it exports the part as DXF and names it the same name as the file name. All of that works excellently, however, the DXFs that get created have extra lines (bend lines) and all the line segments are not joined together. Our plasma table requires all contours to be joined to run. Right now we are going in and manually joining the line segments in autocad using the join command. I noticed though that if I use the built in "export face as" command the DXF that gets created has no bend lines and it comes out as a joined contour. I believe the code used to create the actual DXFs in our current rule is utilizing some sort of flat pattern drawing view. I am posting the code below and my questions are;

 

Could someone help in altering the current code to not export bend lines and make the line segments joined?

OR

Could someone replace the current DXF creation kernel with the "export face as" method?

 

here is our rule

'define the active document as an assembly file
Dim oAsmDoc As AssemblyDocument

oAsmDoc = ThisApplication.ActiveDocument

oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName) -4)



'check that the active document is an assembly file
If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then

MessageBox.Show("Please run this rule from the assembly file.", "iLogic")

Exit Sub

End If

'get user input
RUsure = MessageBox.Show ( _
"This will create a DXF file for all of the assembly components that was created using the sheet metal template." _
& vbLf & "This rule expects that the part file is saved." _
& vbLf & " " _
& vbLf & "Are you sure you want to create DXF for all of the assembly components?" _
& vbLf & "This could take a while.", "iLogic  - Batch Output DXFs ",MessageBoxButtons.YesNo)

If RUsure = vbNo Then

Return

Else

End If

oPath = "R:\email\Burn Table" 'this will need to be modified for your use

oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

oContext = ThisApplication.TransientObjects.CreateTranslationContext

oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism

oOptions = ThisApplication.TransientObjects.CreateNameValueMap

'get DXF target folder path
oFolder = oPath & "\" & oAsmName

'Check for the DXF folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then

    System.IO.Directory.CreateDirectory(oFolder)

End If
'- - - - - - - - - - - - -

'- - - - - - - - - - - - -Component  - - - - - - - - - - - -
'look at the files referenced by the assembly
Dim oRefDocs As DocumentsEnumerator

oRefDocs = oAsmDoc.AllReferencedDocuments

Dim oRefDoc As Document


'work the drawing files for the referenced models
'this expects that the model has been saved
For Each oRefDoc In oRefDocs

iptPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentName) - 3) & "ipt"

    'check that model is saved
If(System.IO.File.Exists(iptPathName)) Then

                Dim oDrawDoc As PartDocument

                oDrawDoc = ThisApplication.Documents.Open(iptPathName, True)

            oFileName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName))

Try

                'Set the DXF target file name
                ofilename = Left(oRefDoc.displayname, Len(oRefDoc.DisplayName) - 3)

oDataMedium.FileName = oFolder & "\" & oFileName & "dxf"

Dim oCompDef As SheetMetalComponentDefinition

oCompDef = oDrawDoc.ComponentDefinition

If oCompDef.HasFlatPattern = False Then

oCompDef.Unfold

Else

   oCompDef.FlatPattern.Edit

End If

Dim sOut As String

'this assigns colors to the different layers, this can also be modified

sOut = "FLAT PATTERN DXF?AcadVersion=2004" _
+ "&OuterProfileLayer=OUTER_PROF&OuterProfileLayerColor=255;165;0" _
+ "&InteriorProfilesLayer=INNER_PROFS&InteriorProfilesLayerColor=124;252;0" _
+ "&FeatureProfileLayer=FEATURE&FeatureProfileLayerColor=255;0;255" _
+ "&ArcCentersLayer=CENTERS&ArcCentersLayerColor=135;206;235" _
+ "&IV_Arc_Centers&InvisibleLayers=IV_Tangent;IV_Bend;IV_Bend_Down;IV_Bend_Up&IV_Arc_Centers&InvisibleLayersColor=135;206;235"


oCompDef.DataIO.WriteDataToFile( sOut, oDataMedium.FileName)

'just for checking to see if its works coretcly
'i=MessageBox.Show(oDataMedium.FileName, "Title",MessageBoxButtons.OKCancel)

'MessageBox.Show(i,"title",MessageBoxButtons.OK)

'If i=2 Then

'Exit Sub

'End If

oCompDef.FlatPattern.ExitEdit

Catch

End Try
               
oDrawDoc.Close

Else

End If

Next

0 Likes
Accepted solutions (2)
1,220 Views
4 Replies
Replies (4)
Message 2 of 5

cameron.houston
Enthusiast
Enthusiast

Additionally,

 

here is some ilogic code that I found that utilizes the Export Face As command for automated DXF creation. However, it requires a manual face selection. If this could be put into the above code using an automated face selection of the top face of the flat pattern that would be ideal.

 

'Export selected face to same place as file

If
ThisApplication.ActiveDocument.SelectSet.Count = 0 Then
MsgBox("Face not selected. Aborting Rule!")
Exit Sub
End If

oFileName = ThisDoc.PathAndFileName(False) & ".dxf"

Dim oCmdMgr As CommandManager
oCmdMgr = ThisApplication.CommandManager

Call oCmdMgr.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, oFileName)
Call oCmdMgr.ControlDefinitions.Item("GeomToDXFCommand").Execute 

 

 

0 Likes
Message 3 of 5

JelteDeJong
Mentor
Mentor

hi

put this iLogic code in a sheet metal file. it should create a dxf "C:\temp\TopFace.dxf" from the top face.

Dim doc As PartDocument = ThisApplication.ActiveDocument

Dim sheetMetalDef As SheetMetalComponentDefinition = doc.ComponentDefinition
If (Not sheetMetalDef.HasFlatPattern()) Then
    sheetMetalDef.Unfold()
End If

sheetMetalDef.FlatPattern.Edit()
doc.SelectSet.Select(sheetMetalDef.FlatPattern.TopFace)

ThisApplication.CommandManager.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, "C:\temp\TopFace.dxf")
Dim cDef As ControlDefinition = ThisApplication.CommandManager.ControlDefinitions.Item("GeomToDXFCommand")
cDef.Execute()

sheetMetalDef.FlatPattern.ExitEdit()

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 4 of 5

cameron.houston
Enthusiast
Enthusiast
Accepted solution

Hey hjalte79,

 

Thanks for the bit of code you provided. What I ended up doing was taking that kernel of code and worked it into my existing rule, replacing the old method of DXF creation with the GeomtoDXF command route. This did provide the result I was looking for. For reference here is my code as constructed now below.

 

Thanks,

 

Cameron

 

 

 

 

Dim oAsmDoc As AssemblyDocument

oAsmDoc = ThisApplication.ActiveDocument

oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName) -4)

 

'check that the active document is an assembly file
If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then

MessageBox.Show("Please run this rule from the assembly file.", "iLogic")

Exit Sub

End If

'get user input
RUsure = MessageBox.Show ( _
"This will create a DXF file for all of the assembly components that was created using the sheet metal template." _
& vbLf & "This rule expects that the part file is saved." _
& vbLf & " " _
& vbLf & "Are you sure you want to create DXF for all of the assembly components?" _
& vbLf & "This could take a while.", "iLogic - Batch Output DXFs ",MessageBoxButtons.YesNo)

If RUsure = vbNo Then

Return

Else

End If

oPath = "C:\" 'this will need to be modified for your use

oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

oContext = ThisApplication.TransientObjects.CreateTranslationContext

oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism

oOptions = ThisApplication.TransientObjects.CreateNameValueMap

'get DXF target folder path
oFolder = oPath & "\" & oAsmName

'Check for the DXF folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then

System.IO.Directory.CreateDirectory(oFolder)

End If
'- - - - - - - - - - - - -

'- - - - - - - - - - - - -Component - - - - - - - - - - - -
'look at the files referenced by the assembly
Dim oRefDocs As DocumentsEnumerator

oRefDocs = oAsmDoc.AllReferencedDocuments

Dim oRefDoc As Document


'work the drawing files for the referenced models
'this expects that the model has been saved
For Each oRefDoc In oRefDocs

iptPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentName) - 3) & "ipt"

'check that model is saved
If(System.IO.File.Exists(iptPathName)) Then

Dim oDrawDoc As PartDocument

oDrawDoc = ThisApplication.Documents.Open(iptPathName, True)

oFileName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName))

Try

'Set the DXF target file name
oFileName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName) - 3)

oDataMedium.FileName = oFolder & "\" & oFileName & "dxf"

Dim oCompDef As SheetMetalComponentDefinition

oCompDef = oDrawDoc.ComponentDefinition

If (Not oCompDef.HasFlatPattern()) Then
oCompDef.Unfold()
End If

oCompDef.FlatPattern.Edit()
oDrawDoc.SelectSet.Select(oCompDef.FlatPattern.TopFace)

ThisApplication.CommandManager.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, oDataMedium.FileName)
Dim cDef As ControlDefinition = ThisApplication.CommandManager.ControlDefinitions.Item("GeomToDXFCommand")
cDef.Execute()

oCompDef.FlatPattern.ExitEdit()


Catch

End Try

oDrawDoc.Close

Else

End If

Next

 
0 Likes
Message 5 of 5

cameron.houston
Enthusiast
Enthusiast
Accepted solution

Additional update for those who might like to use this as well. I added additional functionality so that it only searches for flat patterns from parts that have Descriptions such as " Plate, Sheet, etc" that way it does open up ever nut and bolt and washer in an entire assembly. Here it is:

 

 

Dim oUnknownDoc As Document

oUnknownDoc = ThisApplication.ActiveDocument

If oUnknownDoc.DocumentType = kAssemblyDocumentObject Then
	MessageBox.Show("I am an Assembly! But I am more then just the sum of my parts")
	
	'[
Dim oAsmDoc As AssemblyDocument

oAsmDoc = ThisApplication.ActiveDocument

oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName) -4)



'['check that the active document is an assembly file
If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then

MessageBox.Show("Please run this rule from the assembly file.", "iLogic")

Exit Sub

End If
']
'[get user input
RUsure = MessageBox.Show ( _
"This will create a DXF file for all of the assembly components that were created using the sheet metal template." _
& vbLf & " " _
& vbLf & "Be sure the desired part files have a flat patterns and are oriented correctly" _
& vbLf & " " _
& vbLf & "Are you sure you want to create DXF for all of the assembly components?" _
& vbLf & "This could take a while.", "iLogic  - Batch Output DXFs ",MessageBoxButtons.YesNo)

If RUsure = vbNo Then

Return

Else

End If
']

'[
oPath = "\\DATAserver\W\ENG\DXF Files\INBOX" 'take the DXFs to the DXF folder inbox on the network

oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
']- - - - - - - - - - - - -

'- - - - - - - - - - - - -Component  - - - - - - - - - - - -
'look at the files referenced by the assembly
Dim oRefDocs As DocumentsEnumerator

oRefDocs = oAsmDoc.AllReferencedDocuments

Dim oRefDoc As Document


'[Go through each part file in the assembly and run the below routine
For Each oRefDoc In oRefDocs

iptPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentName) -3) & "ipt"

'Get the Material Iproperty of the Part for comparison in the If statement below
Dim oPartDoc As String
	oPartDoc = oRefDoc.PropertySets.Item("Design Tracking Properties").Item("Description").Value
	
	oMaterial = Left(oPartDoc,5)
'[ if material in iproperties is one of the required get flat pattern and export 	
If oMaterial = "SHEET" Or oMaterial = "PLATE" Or oMaterial = "DIAMO"
   
                Dim oDrawPartDoc As PartDocument

                oDrawPartDoc = ThisApplication.Documents.Open(iptPathName, True)

            	'Get the full file name of the document
				oFileName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName))

Try

                'Set the DXF target file name as the full file name less "ipt"
                oFileName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName) - 3)

oDataMedium.FileName = oPath & "\" & oFileName & "dxf"

Dim oCompDef As SheetMetalComponentDefinition

oCompDef = oDrawPartDoc.ComponentDefinition

If (Not oCompDef.HasFlatPattern()) Then
    oCompDef.Unfold()
End If


oCompDef.FlatPattern.Edit()
oDrawPartDoc.SelectSet.Select(oCompDef.FlatPattern.TopFace)

ThisApplication.CommandManager.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, oDataMedium.FileName)
Dim cDef As ControlDefinition = ThisApplication.CommandManager.ControlDefinitions.Item("GeomToDXFCommand")
cDef.Execute()

oCompDef.FlatPattern.ExitEdit()


Catch

End Try
               
oDrawPartDoc.Close

Else

End If
']
Next
']
']
	
Else If oUnknownDoc.DocumentType = kPartDocumentObject Then
	MessageBox.Show("I'm just a part, ya, I'm only a part, ya! ")	
	
'[	
Dim oPartDoc As PartDocument

oPartDoc = ThisApplication.ActiveDocument

oPartName = Left(oPartDoc.DisplayName, Len(oPartDoc.DisplayName) -4)

'[get user input
RUsure = MessageBox.Show ( _
"This will create a DXF file for the given part." _
& vbLf & " " _
& vbLf & "Be sure the part has a flatpattern and is oriented correctly" _
& vbLf & " " _
& vbLf & " " _
& vbLf & "This could take a while.", "iLogic  - Batch Output DXFs ",MessageBoxButtons.YesNo)

If RUsure = vbNo Then

Return

Else

End If
']

'[
oPath = "\\DATAserver\W\ENG\DXF Files\INBOX" 'take the DXFs to the DXF folder inbox on the network

oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
']- - - - - - - - - - - - -

iptPathName = Left(oPartDoc.FullDocumentName, Len(oPartDoc.FullDocumentName) -3) & "ipt"
                oDrawDoc = ThisApplication.Documents.Open(iptPathName, True)

            

Try

                

oDataMedium.FileName = oPath & "\" & oPartName & ".dxf"

Dim oCompDef As SheetMetalComponentDefinition

oCompDef = oDrawDoc.ComponentDefinition

If (Not oCompDef.HasFlatPattern()) Then
    oCompDef.Unfold()
End If

oCompDef.FlatPattern.Edit()
oDrawDoc.SelectSet.Select(oCompDef.FlatPattern.TopFace)

ThisApplication.CommandManager.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, oDataMedium.FileName)
Dim cDef As ControlDefinition = ThisApplication.CommandManager.ControlDefinitions.Item("GeomToDXFCommand")
cDef.Execute()

oCompDef.FlatPattern.ExitEdit()


Catch

End Try
               
oDrawDoc.Close

']


End If
0 Likes