Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic DXF Export from Sheet Metal Part

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
Anonymous
3062 Views, 9 Replies

iLogic DXF Export from Sheet Metal Part

Hello!

 

I found an iLogic rule from the Internet, but somehow it doesn't export my Sheet Metal part. I cant quite get what is wrong with the code. Is there maybe anybody more fluent to help me out with my issue?

 

 

 

Dim partDoc As PartDocument
oAsmDoc = ThisApplication.ActiveDocument
oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName) -4)
If ThisApplication.ActiveDocument.DocumentType <> kPartDocumentObject Then

End If
oPath = ThisDoc.Path
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap

oFolder = "C:\Temp"
'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

Dim oRefDocs As DocumentsEnumerator
oRefDocs = oAsmDoc.AllReferencedDocuments
Dim oRefDoc As Document
For Each oRefDoc In oRefDocs
iptPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentName) - 3) & "ipt"
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

CustomName =iProperties.Value(oFileName, "Custom", "PF_PRT_ZNR")
Catch
End Try

oDataMedium.FileName = oFolder & "\" & CustomName  & "\ " & 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
sOut = "FLAT PATTERN DXF?AcadVersion=2004&RebaseGeometry=True&OuterProfileLayer=0&OuterProfileLayerColor=0;0;0&InteriorProfilesLayer=0&InteriorProfilesLayerColor=0;0;0&InvisibleLayers=IV_ARC_CENTERS;IV_TANGENT;IV_ROLL;IV_ROLL_TANGENT;IV_ALTREP_BACK;IV_ALTREP_FRONT;IV_FEATURE_PROFILES_DOWN;IV_FEATURE_PROFILES;IV_TOOL_CENTER_DOWN;DIGI_MARKER_TOOL_1;DIGI_MARKER_TOOL_2;IV_BEND;IV_BEND_DOWN;IV_INNER_PROFILES;"
oCompDef.DataIO.WriteDataToFile(sOut,oDataMedium.FileName)
oCompDef.FlatPattern.ExitEdit


oDrawDoc.Close
Else
End If
Next
9 REPLIES 9
Message 2 of 10
mcgyvr
in reply to: Anonymous

What specifically are you trying to do?

Just create a dxf from a sheet metal part during save of that part or something?

Run a rule in an assembly during save or something and export dxf for ALL sheet metal parts?

Something else?

 

Its often best to describe exactly what you are trying to do vs only letting us in on what you think the solution is..

 



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
Message 3 of 10
S_May
in reply to: Anonymous

'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 asembly components that are sheet metal." _
& 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 = ThisDoc.Path
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
'get DXF target folder path
oFolder = oPath & "\" & oAsmName & " DXF Files"
'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 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

Try
CustomName =iProperties.Value(oFileName, "Custom", "PF_PRT_ZNR")
Catch
CustomName ="XXX" 'Wert, wenn iPropertie PF_PRT_ZNR nicht existiert
End Try

oDataMedium.FileName = oFolder & "\" & CustomName  & " " & 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
sOut = "FLAT PATTERN DXF?AcadVersion=2004&OuterProfileLayer=IV_OUTER_PR​OFILE"
oCompDef.DataIO.WriteDataToFile( sOut, oDataMedium.FileName)
'just for check 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

 

https://knowledge.autodesk.com/de/community/screencast/ecfa2a59-e898-43be-8177-14e802d9cf8b

 

 

Message 4 of 10
S_May
in reply to: Anonymous

 

Sub Main

DefaultChoice = True

ExportInner = InputRadioBox("Choose Profile to Export", "Inner", "Outer", DefaultChoice, Title := "Export Flat Pattern DXF")

ExportDxf()

End Sub

 

Public Sub ExportDxf()

    Dim oDoc As PartDocument

    oDoc = ThisApplication.ActiveDocument

 

    Dim oCompDef As SheetMetalComponentDefinition

    oCompDef = oDoc.ComponentDefinition

 

    If oCompDef.HasFlatPattern = False Then

        oCompDef.Unfold

    Else

        oCompDef.FlatPattern.Edit

    End If

 

    Dim sOut As String

      If ExportInner = True Then

          sOut = "FLAT PATTERN DXF?AcadVersion=2004&OuterProfileLayer=IV_INTERIOR_PROFILES"

      Else

      sOut = "FLAT PATTERN DXF?AcadVersion=2004&OuterProfileLayer=IV_OUTER_PROFILE"

      End If

 

    ' Get document's full file name

    Dim sFname As String

    sFname = oDoc.FullFileName

 

    ' The file format will depend on the extension

    ' Set file name extension to ".DXF"

    sFname = Left$(sFname, Len(sFname) - 3) & "dxf"

 

    oCompDef.DataIO.WriteDataToFile( sOut, sFname)

 

End Sub

 

 

Message 5 of 10
Anonymous
in reply to: S_May

Thank you for the reply!

I was trying to export DXF from Sheet metal part file.

Message 6 of 10
Anonymous
in reply to: Anonymous

The Macro seems to work fine for me. Is it possible to give it a command that it will save the DXF file to the specific folder every time? 

Message 7 of 10
S_May
in reply to: Anonymous

@Anonymous 

 

this is not possible for reasons of time 😥
Message 8 of 10
Anonymous
in reply to: S_May

Thank you anyway! 👍

Message 9 of 10
abdullah_shaikh
in reply to: Anonymous

Hi, your both codes are  running perfect , may you update the code to remove bending lines?

Message 10 of 10
abdullah_shaikh
in reply to: S_May

Hi, your both codes are  running perfect , may you update the code to remove bending lines?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report