Ilogic help exporting ipt flat pattern to dxf.

Ilogic help exporting ipt flat pattern to dxf.

clintwilkinson
Contributor Contributor
6,364 Views
10 Replies
Message 1 of 11

Ilogic help exporting ipt flat pattern to dxf.

clintwilkinson
Contributor
Contributor

Hi all.

It's been a while since I posted something. But now I need some help.

I recently found this iLogic code to export *.ipt flat patterns to dxf. It does almost everything I require. But I need to tweak it a little.

1. I need for the code to ask where the Save destination folder will be. (Rather than me going into the code to change the "SETFilePath".

2. I would like the "File Save As" name to be set to a specific value from within the part "Custom iProperties". In this case it would be the value associated with "ProfileFileName".

3. This code exports every line contained in the Flat Pattern. (Eg. Outer profile edge, Fold Lines & Fold extents lines).

I only need it to export the Outer Edge Profile & if possible that layer is to be exported as "Layer 0".

 

Any help would be appreciated.

The code is below.

 

'Code by @ClintBrown3D originally posted at https://clintbrown.co.uk/DXF
'Set your filepath here:
SETFilePath = "C:\Temp"

Dim partDoc As PartDocument
If ThisApplication.ActiveDocument.DocumentType <> kPartDocumentObject Then
MessageBox.Show ("Please open a part document", "iLogic")
End If

'Check for flat pattern >> create one if needed
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

'DXF Settings
Dim sOut As String
Dim sPATH As String
sOut = "FLAT PATTERN DXF?AcadVersion=2000&OuterProfileLayer=IV_INTERIOR_PROFILES"
Dim sFname As String
sFname = SETFilePath & "\" & ThisDoc.FileName(False) & ".dxf"

'Export the DXF and fold the model back up
oCompDef.DataIO.WriteDataToFile( sOut, sFname)
Dim oSMDef As SheetMetalComponentDefinition
oSMDef = oDoc.ComponentDefinition
oSMDef.FlatPattern.ExitEdit

'ThisApplication.StatusBarText = "@ClintBrown3D: DXF saved to: " & sFname
MessageBox.Show("DXF saved to: " & sFname, "@ClintBrown3D: Success!")

0 Likes
Accepted solutions (2)
6,365 Views
10 Replies
Replies (10)
Message 2 of 11

bhavik4244
Collaborator
Collaborator
Accepted solution

@clintwilkinson 

 

This may work 🙂

 

'Set your filepath here:
SETFilePath = "C:\Temp"

Dim partDoc As PartDocument
If ThisApplication.ActiveDocument.DocumentType <> kPartDocumentObject Then
MessageBox.Show ("Please open a part document", "iLogic")
End If

'Check for flat pattern >> create one if needed
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

'DXF Settings
Dim sOut As String
Dim sPATH As String
sOut = "FLAT PATTERN DXF?AcadVersion=R12&OuterProfileLayer=Outer"

oDoc = ThisDoc.Document

Dim oFileDlg As Inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)

oFileDlg.InitialDirectory = ThisDoc.WorkspacePath()
oFileDlg.FileName = iProperties.Value("Custom", "ProfileFileNamer") & ".dxf"   'set the property as per requirement
oFileDlg.CancelError = True
On Error Resume Next
oFileDlg.ShowSave()
If Err.Number <> 0 Then
MessageBox.Show("No File Saved.", "iLogic: Dialog Canceled")
ElseIf oFileDlg.FileName <> "" Then
MyFile = oFileDlg.FileName
oDoc.SaveAs(MyFile, False) 'True = Save As Copy & False = Save As
End If

'Export the DXF and fold the model back up
oCompDef.DataIO.WriteDataToFile( sOut, oFileDlg.FileName )
Dim oSMDef As SheetMetalComponentDefinition
oSMDef = oDoc.ComponentDefinition
oSMDef.FlatPattern.ExitEdit

'ThisApplication.StatusBarText = "@ClintBrown3D: DXF saved to: " & sFname
MessageBox.Show("DXF saved to: " & oFileDlg.FileName , "@ClintBrown3D: Success!")

 


Bhavik Suthar
Message 3 of 11

bhavik4244
Collaborator
Collaborator
Accepted solution

@clintwilkinson 

 

Replace sOut in code with below line to just get the outer profile in dxf.

 

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;"

 


Bhavik Suthar
Message 4 of 11

DANIEL.DELANEY
Advocate
Advocate

Hi @bhavik4244,

Just wondering if you could help? I've searched the forums and cant work it out. Today is my first day in iLogic, so unfortunately, my level of experience is that of complete novice. I've managed to get a flat pattern from IPT to a DXF with some extra custom iPropertie values in the part number, so that's good. What I also need though, is for the DXF to be an attachment of the IPT.

I did find this, but its for an assembly, and seeing as iLogic code is kind of like reading Kanji to me, I cant decipher what to do to adapt for a part.  Solved: Attach dxf to ipt via "Insert Object" and "Create from File" using iLogic - Autodesk Communi...

 

Any help would be greatly appreciated. Thanks in advance.

Regards,

Daniel

 

Ps: This is what I have, that I got to work so far:

(I have a feeling I dont even need the Sub CadlinePathProperty()

Sub Main
DefaultChoice = True
CadlinePathProperty()
Cadline()
End Sub
 
Sub CadlinePathProperty()
Dim FilePATH As String = "FilePATH"
customPropertySet = ThisDoc.Document.PropertySets.Item _
("Inventor User Defined Properties")
Try
         prop= customPropertySet.Item(FilePATH)
Catch
            customPropertySet.Add("", FilePATH)
End Try
If iProperties.Value("Custom", "FilePATH") = "" 
Else
End If
Dim partDoc As PartDocument
If ThisApplication.ActiveDocument.DocumentType <> kPartDocumentObject Then
MessageBox.Show ("Please open a part document", "iLogic")
End If
FilePATH = ThisDoc.PathAndFileName(False)
End Sub
 
Public Sub Cadline()
    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
    Dim sPATH As String
    sPATH = ThisDoc.Path
    sOut = "FLAT PATTERN DXF?AcadVersion=2000&OuterProfileLayer=IV_INTERIOR_PROFILES"
    Dim sFname As String
    sFname = sPATH & "\" & ThisDoc.FileName(False) & "-" & iProperties.Value("Custom", "MATL.") & "-" & iProperties.Value("Custom", "HT.") & "THK" & ".dxf"
    MessageBox.Show("DXF SAVED TO: " & sFname ,"DXF Saved", MessageBoxButtons.OK)
    oCompDef.DataIO.WriteDataToFile( sOut, sFname)
  oDoc = ThisApplication.ActiveDocument
Dim oSMDef As SheetMetalComponentDefinition
oSMDef = oDoc.ComponentDefinition
oSMDef.FlatPattern.ExitEdit


End Sub

 

0 Likes
Message 5 of 11

bhavik4244
Collaborator
Collaborator

@DANIEL.DELANEY 

 

sorry for the very late reply.

 

here you go 🙂

 

you need to add a line only.

 

Sub Main
DefaultChoice = True
CadlinePathProperty()
Cadline()
End Sub
 
Sub CadlinePathProperty()
Dim FilePATH As String = "FilePATH"
customPropertySet = ThisDoc.Document.PropertySets.Item _
("Inventor User Defined Properties")
Try
         prop= customPropertySet.Item(FilePATH)
Catch
            customPropertySet.Add("", FilePATH)
End Try
If iProperties.Value("Custom", "FilePATH") = "" 
Else
End If
Dim partDoc As PartDocument
If ThisApplication.ActiveDocument.DocumentType <> kPartDocumentObject Then
MessageBox.Show ("Please open a part document", "iLogic")
End If
FilePATH = ThisDoc.PathAndFileName(False)
End Sub
 
Public Sub Cadline()
    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
    Dim sPATH As String
    sPATH = ThisDoc.Path
    sOut = "FLAT PATTERN DXF?AcadVersion=2000&OuterProfileLayer=IV_INTERIOR_PROFILES"
    Dim sFname As String
    sFname = sPATH & "\" & ThisDoc.FileName(False) & "-" & iProperties.Value("Custom", "MATL.") & "-" & iProperties.Value("Custom", "HT.") & "THK" & ".dxf"
    MessageBox.Show("DXF SAVED TO: " & sFname ,"DXF Saved", MessageBoxButtons.OK)
    oCompDef.DataIO.WriteDataToFile( sOut, sFname)
  oDoc = ThisApplication.ActiveDocument
Dim oSMDef As SheetMetalComponentDefinition
oSMDef = oDoc.ComponentDefinition
oSMDef.FlatPattern.ExitEdit

oDoc.ReferencedOLEFileDescriptors.Add(sFname , OLEDocumentTypeEnum.kOLEDocumentLinkObject)
End Sub

 

 


Bhavik Suthar
0 Likes
Message 6 of 11

DANIEL.DELANEY
Advocate
Advocate

Hi @bhavik4244 

No dramas on the delay. Thanks, I appreciate it! Ill give that a go.

On a side note; is there any resource you are aware of that I can refer to, to learn iLogic? Or is it just something you've picked up?

Cheers

Daniel

0 Likes
Message 7 of 11

bhavik4244
Collaborator
Collaborator

Hi @DANIEL.DELANEY 

 

I would recommend the YouTube series of KETIV on iLogic. Moreover, it good to see the Autodesk University sessions for learning.

 

You may reach to me on bhavik4244@gmail.com if you need any other help, since I check my email regularly but availability on Forum is not frequent nowadays.

 

Cheers!


Bhavik Suthar
Message 8 of 11

DANIEL.DELANEY
Advocate
Advocate

Hi @bhavik4244

Thanks very much, Ill check out those suggestions. 

And worst case, if I get really stumped, I'll flick you an email. Thanks for the support option.

Also, your extra line of text worked perfectly; my boss now thinks I'm some kind of magician! 😆

More importantly though, that process makes my design & export process ALOT easier to manage!

Thanks again, its much appreciated.

Cheers

Daniel

Message 9 of 11

lgets2013NGTMB
Community Visitor
Community Visitor

Hello, thank you for your code but when I am exporting I dont need bending line to be in exported DXF, what can I do?

0 Likes
Message 10 of 11

clintwilkinson
Contributor
Contributor

Replace the Line

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

with

 sOut = "FLAT PATTERN DXF?AcadVersion=2007" _
+ "&OuterProfileLayer=0&InteriorProfilesLayer=0" _
+ "&InvisibleLayers=IV_TANGENT;IV_ARC_CENTERS;IV_BEND;IV_BEND_DOWN;IV_FEATURE_PROFILES;IV_FEATURE_PROFILES_DOWN" _
+ "FeatureProfilesUpLayer=Splines&SimplifySplines=True&SplineTolerance=0.00001&MergeProfilesIntoPolyline=True" _
+ "&BendLayerColor=255;255;0" _
+ "&FeatureProfilesUpLayerColor=255;0;0" _
+ "&FeatureProfilesDownLayerColor=0;128;128"

0 Likes
Message 11 of 11

louis485W7
Explorer
Explorer

Hi Bhavik,

 

I am having a similar problem to others in this thread and can't find help anywhere else. I will appreciate any insight you are willing to provide. I am pretty fresh to iLogic and even coding in general, however, I have written the iLogic below using a couple of different sources and help from AI chat.

 

My goal is save a .dxf file from an .ipt with the outer and inner profiles on layer 0, in white, and a continuous line. Then the bend and bend down layer saved to a layer called Fold_Lines and coloured red with a dashed line.

 

I can output the file fine but my issues start when trying to define the layers, colours and line types. I am using Inventor Pro 2024.

 

' Define the DXF export path
Dim outputFolder As String = System.IO.Path.GetDirectoryName(ThisDoc.Document.FullFileName)
Dim dxfSubFolder As String = System.IO.Path.Combine(outputFolder, "DXF")
If Not System.IO.Directory.Exists(dxfSubFolder) Then
    System.IO.Directory.CreateDirectory(dxfSubFolder)
End If

Dim dxfFileName As String = System.IO.Path.Combine(dxfSubFolder, ThisDoc.Document.DisplayName & ".dxf")

' Ensure the document is a part file and has a sheet metal flat pattern
If ThisApplication.ActiveDocument.DocumentType <> kPartDocumentObject Then
    MessageBox.Show("Please open a part document to export a DXF.", "iLogic DXF Export", MessageBoxButtons.OK, MessageBoxIcon.Warning)
    Return
End If

Dim partDoc As PartDocument = ThisApplication.ActiveDocument
Dim sheetMetalCompDef As SheetMetalComponentDefinition
Try
    sheetMetalCompDef = partDoc.ComponentDefinition
    sheetMetalCompDef.FlatPattern.Edit ' Activate the flat pattern if it exists
Catch ex As Exception
    MessageBox.Show("The part is not a sheet metal part or doesn't have a flat pattern.", "iLogic DXF Export", MessageBoxButtons.OK, MessageBoxIcon.Warning)
    Return
End Try

' Configure DXF export options with custom layers, colors, and line types
Dim dxfOptions As String = "FLAT PATTERN DXF?AcadVersion=2018&RebaseGeometry=True"

' Set up layers, colors, and line types
dxfOptions &= "&OuterProfileLayer=0"
dxfOptions &= "&OuterProfileLayerColor=0;0;0" ' White
dxfOptions &= "&InnerProfileLayer=0"
dxfOptions &= "&InnerProfileLayerColor=0;0;0" ' White
dxfOptions &= "&BendLinesLayer=Fold_Lines"
dxfOptions &= "&BendLinesLayerColor=255;0;0" ' Red
dxfOptions &= "&BendLinesLayerLineType=Dashed"
dxfOptions &= "&BendDownLinesLayer=Fold_Lines"
dxfOptions &= "&BendDownLinesLayerColor=255;0;0" ' Red
dxfOptions &= "&BendDownLinesLayerLineType=Dashed"

' Optionally hide layers that are not needed in the DXF
dxfOptions &= "&InvisibleLayers=IV_ARC_CENTERS;IV_TANGENT;IV_ROLL;IV_ROLL_TANGENT;IV_ALTREP_BACK;IV_ALTREP_FRONT"

' Export the DXF with the specified options
Try
    sheetMetalCompDef.DataIO.WriteDataToFile(dxfOptions, dxfFileName)
    MessageBox.Show("DXF export successful! Saved to: " & dxfFileName, "iLogic DXF Export", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
    MessageBox.Show("Failed to export DXF: " & ex.Message, "iLogic DXF Export", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try

' Exit the flat pattern edit mode to return to the folded model
sheetMetalCompDef.FlatPattern.ExitEdit

Thank you for any thoughts you might have. It has been doing my head in...

 

Cheers,

0 Likes