Modify layers before exporting DXF file using iLogic rule

Modify layers before exporting DXF file using iLogic rule

fsdolphin
Collaborator Collaborator
5,905 Views
15 Replies
Message 1 of 16

Modify layers before exporting DXF file using iLogic rule

fsdolphin
Collaborator
Collaborator

Hi,

 

I'm currently trying to automate the process of exporting a DXF in Inventor using iLogic. Luckily I was able to find this article which contains the code for the exporting process, this code does almost what I was looking for except that I would like to modify some layers before doing the export.

 

How can I modify the following code to be able to modify layers before exporting the DXF?

 

FYI- I looked at the APIs for the but I'm not sure how what I need.

http://help.autodesk.com/view/INVNTOR/2018/ENU/?query=FlatPattern&userType=Developer

 

SyntaxEditor Code Snippet

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") = "" Then
        iProperties.Value("Custom", "FilePATH") = "C:\Testing Folder"
    End If

    Dim partDoc As PartDocument

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

    FilePATH = InputBox("Enter a FilePATH for part file", "iLogic", iProperties.Value("Custom", "FilePATH"))

    iProperties.Value("Custom", "FilePATH") = FilePATH
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 = iProperties.Value("Custom", "FilePATH")
    sOut = "FLAT PATTERN DXF?AcadVersion=2004&OuterProfileLayer=IV_INTERIOR_PROFILES"

    Dim sFname As String
    sFname = sPATH & "\" & ThisDoc.FileName(False) & ".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

 

This is how the layers should be modified to...

 

dxf layers.jpg

0 Likes
5,906 Views
15 Replies
Replies (15)
Message 2 of 16

Anonymous
Not applicable

Hi fsdolphin

 

That code was from my blog on Cadline Community 🙂

 

The settings for the layers are saved in a .ini file that Inventor references for the export. These files are stored in your design data folder, which by default should look something like this: C:\Users\Public\Documents\Autodesk\Inventor 2018\Design Data\DWG-DXF.

 

To create a new .ini file, set up your layers are required, and then choose "Save Configuration". Best practice would be save this .ini file to the design data location.

2017-07-27_08h39_28.png

 

Manually publish a DXF, and Inventor should now remember the last .ini file you used, so the iLogic code should now export out the DXF's with the layers you set up.

 

I hope this makes sense

Message 3 of 16

Anonymous
Not applicable

Another option is to explicitly add the .ini file and location to the code, as shown below:

 

Dim strIniFile As String
        strIniFile = "C:\Users\Public\Documents\Autodesk\Inventor 2018\Design Data\DWG-DXF\YOURiniNAME.ini"

        ' Create the name-value that specifies the ini file to use.
        oOptions.Value("Export_Acad_IniFile") = strIniFile
0 Likes
Message 4 of 16

fsdolphin
Collaborator
Collaborator

@Anonymous First of all thanks a lot for the code, very useful.

 

I already have a .ini file but saving manually and then trying the iLogic rule as you suggested it doesn't work, it doesn't remember the settings.

 

FYI - The .ini file is saved/located in a local network not in the Design Data folder, I'm not sure if it make a difference. 

 

Anyways, I would rather have a reference to the file in my code.

 

How can I reference the .ini file in code?

 

Thanks a lot.

0 Likes
Message 5 of 16

fsdolphin
Collaborator
Collaborator

@Anonymous I really like your method but I can not make it work.

 

Where exactly should I be adding your code? 

 

 

Where do I add this line of code

oOptions.Value("Export_Acad_IniFile") = strIniFile

 

I got error: `oOptions` is not declared. It may be inaccessible due to its protection level.

 

Thanks a lot!

0 Likes
Message 6 of 16

SašoPrijatelj
Advocate
Advocate

try adding this before oOptions.value:

 

Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap

 

-----------------------------------------------------------------------
AutoDXF - automatic flat pattern creation and batch export to DXF for Inventor

Please use "Accept as Solution" & give "Kudos" if this response helped you.
Message 7 of 16

fsdolphin
Collaborator
Collaborator

@SašoPrijatelj Thanks a lot for your comments. By adding the code you suggested did silence the error, but it didn't apply the settings from my .ini file. The main issue is that I'm not sure where exactly does the following block of code needs to go...

 

SyntaxEditor Code Snippet

    Dim oOptions As NameValueMap
    oOptions = ThisApplication.TransientObjects.CreateNameValueMap
    
    Dim strIniFile As String
    strIniFile = "C:\Inventor Working\Libraries\configurations\Kenall DXF Configuration.ini"
    ' Create the name-value that specifies the ini file to use.
    oOptions.Value("Export_Acad_IniFile") = strIniFile

 

 

I added it at the beginning of the Cadline subroutine, but the settings in my .ini file do not get applied. I don't get any errors it just doesn't see the .ini file.

 

I this where the link to the .ini file should be?

 

SyntaxEditor Code Snippet

Public Sub Cadline()
Dim oOptions As NameValueMap oOptions = ThisApplication.TransientObjects.CreateNameValueMap Dim strIniFile As String strIniFile = "C:\Inventor Working\Libraries\configurations\My Configurations.ini" ' Create the name-value that specifies the ini file to use. oOptions.Value("Export_Acad_IniFile") = strIniFile 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 = iProperties.Value("Custom", "FilePATH") sOut = "FLAT PATTERN DXF?AcadVersion=2004&OuterProfileLayer=IV_INTERIOR_PROFILES" Dim sFname As String sFname = sPATH & "\" & ThisDoc.FileName(False) & ".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 8 of 16

M
Contributor
Contributor

Hi fsdolphin

I'm exactly at the same spot as You, but i might have found something that will help the both of us to some degree.

The link below I've found talk about generating DXF's for sheet metal parts from an Assembly level, but as for me is not fully functional, because it only supports one assembly level of complexity, it doesn't work on multi assembly multisheetmetal part construction without further rewriting.

 

Drive Rule in Sub Sheet Metal part to Export DWG/DXF by DataIO

 

Anyway, for the sake of your post, there is an interesting line of code You can Use, under Sheet metal part rule which might help You to modify some options for the particular layers You are interested in. Anyway for now I have nothing more, and at the moment Im trying to apply that coding into my rule and to expand it, if I have something working I'll post it up.

 

PS.

The code saso & appsUP8FN wrote I personally found only in a rule for exporting DWG/DXF's from a drawing level, not from parts sheet metal one.

 

 

 

APDSU 2015-2021
==========================================================
Please use the "Accept as Solution" and "Give Kudos" functions as appropriate to further enhance the value of these forums.
Message 9 of 16

M
Contributor
Contributor

I've played around a bit and i came with a code that siuts me

 

 

SyntaxEditor Code Snippet
  oDoc = ThisDoc.Document


  'check if the part is a sheet metal part
  If oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
                   
                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 oPath As String
                                
                oPath = ThisDoc.Path & "\DXF Flat" 'my variation to put the DXF in seperate folder
                
                'Check for the file folder and create it if it does not exist
                If Not System.IO.Directory.Exists(oPath) Then
                System.IO.Directory.CreateDirectory(oPath)
                End If
                
                'The actual "ini" file alternative with some options pasted from DataIO post, and customized for my needs
                'In this version Inner and outer layer of flat pattern is put on Layer 0, and the rest of the layers is not included in the file.
                Dim sFname 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" 
                
                'File naming section, I do not use part file name for the DXF, but instead I use fields from iProperities, in this case Description
                Dim iPropDesc As String
                iPropDesc = iProperties.Value("Project", "Description")
                
                sFname = oPath & "\"& iPropDesc &".dxf"
                oCompDef.DataIO.WriteDataToFile(sOut, sFname)
  Else
  End If

 

APDSU 2015-2021
==========================================================
Please use the "Accept as Solution" and "Give Kudos" functions as appropriate to further enhance the value of these forums.
Message 10 of 16

fsdolphin
Collaborator
Collaborator

@M  Thanks a lot for your reply, it helped me a lot. I now have it almost where I need it except one thing, I need IV_BEND and IV_BEND_DOWN as dashed lines. 

 

 

 

 

sOut = "FLAT PATTERN DXF?AcadVersion=2004&RebaseGeometry=True&OuterProfileLayer=0&OuterProfileLayerColor=0;0;0&InteriorProfilesLayer=0&InteriorProfilesLayerColor=0;0;0IV_BEND;IV_BEND_DOWN;IV_OUTER_PROFILE;IV_INTERIOR_PROFILES;IV_FEATURE_PROFILES;IV_FEATURE_PROFILES_DOWN;IV_ALTREP_FRONT;IV_ALTREP_BACK;IV_ROLL_TANGENT;IV_ROLL&InvisibleLayers=IV_TANGENT;IV_TOOL_CENTER;IV_TOOL_CENTER_DOWN;IV_ARC_CENTERS;IV_UNCONSUMED_SKETCHES"
 
Any idea how can I make IV_BEND and IV_BEND_DOWN dashed?
 
 
This is how they should look:
 
IV_TANGENT;                                'Off
IV_TOOL_CENTER;                        'Off
IV_TOOL_CENTER_DOWN;           'Off
IV_ARC_CENTERS;                        'Off
IV_UNCONSUMED_SKETCHES;     'Off

IV_BEND;                                     'On Dashed
IV_BEND_DOWN;                        'On Dashed

IV_OUTER_PROFILE;                     'On Solid
IV_INTERIOR_PROFILES;               'On Solid
IV_FEATURE_PROFILES;                'On Solid
IV_FEATURE_PROFILES_DOWN;   'On Solid
IV_ALTREP_FRONT;                      'On Solid
IV_ALTREP_BACK;                        'On Solid
IV_ROLL_TANGENT;                     'On Solid
IV_ROLL;                                      'On Solid
 
 
0 Likes
Message 11 of 16

fsdolphin
Collaborator
Collaborator

To make IV_BEND and IV_BEND_DOWN dash lines you need to add the following to your sOut string.

 

SyntaxEditor Code Snippet

&BendDownLayerLineType=37639&BendUpLayerLineType=37639

Here is the API documentation where I found the information I needed to modify the line type:

 

http://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-2710DD46-99DE-4599-9293-221D1826BCCB

 

http://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-9F5075D3-00C5-47B3-8BF9-F97E8680B39E

 

http://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-7F7B56B1-793E-450A-8AC6-157EB4891C93

 

 

Here is my final code:

 

SyntaxEditor Code Snippet

  oDoc = ThisDoc.Document

  'check if the part is a sheet metal part
  If oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
                   
    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 oPath As String
                                
    oPath = ThisDoc.Path & "\DXF Flat" 
                
    If Not System.IO.Directory.Exists(oPath) Then
        System.IO.Directory.CreateDirectory(oPath)
    End If
                
    Dim sFname As String
   
    sOut = "FLAT PATTERN DXF?AcadVersion=2004&RebaseGeometry=True&OuterProfileLayer=0&OuterProfileLayerColor=0;0;0&InteriorProfilesLayer=0&InteriorProfilesLayerColor=0;0;0&BendDownLayerColor=255;0;0&BendUpLayerColor=255;0;0&BendDownLayerLineType=37639&BendUpLayerLineType=37639IV_BEND;IV_BEND_DOWN;IV_OUTER_PROFILE;IV_INTERIOR_PROFILES;IV_FEATURE_PROFILES;IV_FEATURE_PROFILES_DOWN;IV_ALTREP_FRONT;IV_ALTREP_BACK;IV_ROLL_TANGENT;IV_ROLL&InvisibleLayers=IV_TANGENT;IV_TOOL_CENTER;IV_TOOL_CENTER_DOWN;IV_ARC_CENTERS;IV_UNCONSUMED_SKETCHES"
               
    sFname = oPath & "\"& "myFile.dxf"
    oCompDef.DataIO.WriteDataToFile(sOut, sFname)
    MessageBox.Show("Your file was saved in the following dirctory: " + sFname)
  Else
    MessageBox.Show("Only sheet metal parts can be exported as DXF. Nice Try! :-)")
  End If

 

Thank you all very much!

 

 

Message 12 of 16

Anonymous
Not applicable

Kudos!

 

I was looking a line of code that would omit all bend lines for sheet metal parts when creating DXFs & found this line of your code:

 

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"

 

 

I added the IV_BEND & IV_BEND_DOWN to the list of Invisible Layers.  Here was my final version of that same line of code:

 

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"

 

Works like a charm!  Thanks!

Message 13 of 16

projetos33
Contributor
Contributor

Alguem poderia me ajudar nesse mesmo caso?

Preciso que a camda IV_FEATURE_PROFILES venha na cor vermelha

0 Likes
Message 14 of 16

Curtis_Waguespack
Consultant
Consultant

@projetos33 , 

Veja este exemplo / See this example.

 

link relacionado / related link:

Inventor 2025 Help | Translate - Sheet Metal to DXF | Autodesk

 

Dim oDoc As PartDocument = ThisDoc.Document
'exit if part is not sheetmetal
If Not oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then Exit Sub

Dim oCompDef As SheetMetalComponentDefinition = oDoc.ComponentDefinition
If oCompDef.HasFlatPattern = False Then oCompDef.Unfold

Dim FolderPath As String = ThisDoc.Path & "\FlatPattern DXFs"
If Not System.IO.Directory.Exists(FolderPath) Then System.IO.Directory.CreateDirectory(FolderPath)
Dim FileName As String = FolderPath & "\" & ThisDoc.FileName(False) & ".dxf"

Dim sOut As String = "FLAT PATTERN DXF?AcadVersion=2004" _
& "&RebaseGeometry=True" _
& "&OuterProfileLayer=IV_OUTER_PROFILE" _
& "&OuterProfileLayerColor=0;0;0" _'black ( white in AutoCAD)
& "&InteriorProfilesLayer=IV_INTERIOR_PROFILES" _
& "&InteriorProfilesLayerColor=255;0;0" _'red
& "&BendDownLayer=IV_BEND_DOWN" _
& "&BendDownLayerColor=255;255;0" _'yellow
& "&BendDownLayerLineType=37639" _
& "&BendUpLayer=IV_BEND" _
& "&BendUpLayerColor=255;255;0" _'yellow
& "&BendUpLayerLineType=37639" _
& "&FeatureProfilesUpLayer=IV_FEATURE_PROFILES" _
& "&FeatureProfilesUpLayerColor=255;0;0" _'red
& "" _'from here down are the layers that will be visible if used
& "IV_BEND;" _
& "IV_BEND_DOWN;" _
& "IV_OUTER_PROFILE;" _
& "IV_INTERIOR_PROFILES;" _
& "IV_FEATURE_PROFILES;" _
& "IV_FEATURE_PROFILES_DOWN;" _
& "IV_ALTREP_FRONT;" _
& "IV_ALTREP_BACK;" _
& "IV_ROLL_TANGENT;" _
& "IV_ROLL" _
& "&InvisibleLayers=" _'move lines below this to turn layers off
& "IV_TANGENT;" _
& "IV_TOOL_CENTER;" _
& "IV_TOOL_CENTER_DOWN;" _
& "IV_ARC_CENTERS;" _
& "IV_UNCONSUMED_SKETCHES"

oCompDef.DataIO.WriteDataToFile(sOut, FileName)
oCompDef.FlatPattern.ExitEdit
MessageBox.Show("DXF out: " + FileName,"iLogic")

 

 

 

EESignature

Message 15 of 16

projetos33
Contributor
Contributor

Muito obrigado, resolveu meu problema. 

Uma outra dúvida se souber, quando eu exporto em DWG ou DXF ele não aparece a imagem em miniatura dentro da pasta, é necessário abrir o arquivo DWG ou DXF e salvar para aparecer.

 

Existe uma forma para aparecer a miniatura do arquivo nas pastas após exportação?

 

Obrigado.

0 Likes
Message 16 of 16

10197112
Explorer
Explorer

How do i apply a custom linetype named LaserCut to the outer line of my flatpattern? for dxf export
Ive defined it in the standard .lin file and im able to use it in sketches when i change the properties of lines.
My goal, is to define the path for the laser, so it leaves 1mm gaps when it cuts the plates outer brim

0 Likes