Help make Ilogic for dxf export work.

Help make Ilogic for dxf export work.

Anonymous
Not applicable
7,115 Views
37 Replies
Message 1 of 38

Help make Ilogic for dxf export work.

Anonymous
Not applicable

I have been working on making an Ilogic rule to create dxf's of all sheet metal parts with the Vendor "LASER" in an assembly and then export and sort them based on thickness and material.  @kevinv has done most of the work on the rule and it runs on his end using Inventor 2020 but for me using Inventor Pro 2018 there is no error code but it doesn't create the files.  If anyone using Inventor 2018 could try to help make it work that would be greatly appreciated.  

0 Likes
7,116 Views
37 Replies
Replies (37)
Message 21 of 38

reine_den_andra
Contributor
Contributor

The code works !!! WOW. I can not thank you enough! I'm so impressed. A whole new world has opened up for me. Thank you so much for taking the time to help with this. It saves hours of work for me at work. THANKS!

0 Likes
Message 22 of 38

reine_den_andra
Contributor
Contributor

The code works !!! WOW. I can not thank you enough! I'm so impressed. A whole new world has opened up for me. Thank you so much for taking the time to help with this. It saves hours of work for me at work. THANKS!

Message 23 of 38

kevinv
Enthusiast
Enthusiast
You are very welcome! I can't even calculate how many hours this code has saved our team of five Inventor users over the years. Sharing it is the right thing to do! I am surprised more people don't inquire about it. Enjoy!
0 Likes
Message 24 of 38

reine_den_andra
Contributor
Contributor

I love this! And that you share this with us. I'm so thankful.

 

Message 25 of 38

Aron.Molnar858QE
Observer
Observer

Hi Kevin,

Just found your code. Works great! Very thankful for sharing it.
I have one question: How can I add sheet metal extents besides the thickness in the generated DXF filenames?


For example, the end result is being:  1300x200x0,7 YD bottom.dxf

I tried to add it myself, but it seems complex.


I have got this code to write the part extents into the part file iProperties, but I cannot get them into the file name.

Public Sub Main()
' Reading the current assembly.
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument

' Reading current assembly component definition.
Dim oAsmDef As AssemblyComponentDefinition
oAsmDef = oAsmDoc.ComponentDefinition

' Reading Child part(leaf occurrences) of the assembly.
Dim oLeafOccs As ComponentOccurrencesEnumerator
oLeafOccs = oAsmDef.Occurrences.AllLeafOccurrences

' Iterate through all part occurrences in assembly.

For Each oOcc In oLeafOccs
	Dim odoc As PartDocument
	Try
		odoc=oOcc.definition.document
		Catch
		End Try
	Dim oSMCD As SheetMetalComponentDefinition
oSMCD = odoc.ComponentDefinition
' Look for Flatpattern
If Not oSMCD.HasFlatPattern Then
 
   oSMCD.Unfold()
   odoc.Update2(True)
   oSMCD.FlatPattern.ExitEdit
Else

End If

Dim fp As FlatPattern = oSMCD.FlatPattern

L = fp.Length*10

W = fp.Width*10	

H = oSMCD.Thickness.Value*10

Dim oList As New ArrayList
oList.Add(L)
oList.Add(W)
oList.Add(H)

Call oList.Sort()

iProperties.Value(oOcc.Name, "Custom", "Length")= oList.Item(2)
iProperties.Value(oOcc.Name,"Custom", "Width") = oList.Item(1)
iProperties.Value(oOcc.Name, "Custom", "Thickness") = oList.Item(0)
Smallest = oList.Item(0)
Middle = oList.Item(1)
Largest = oList.Item(2)
iProperties.Value(oOcc.Name, "Custom", "StockSize") = Largest & " x " & Middle & " x " & Smallest & " "

Next

End Sub



Thanks in advance!

0 Likes
Message 26 of 38

kevinv
Enthusiast
Enthusiast

Hello Aron,

So glad you found this code useful! I will do my best to help you get those values into your dxf file names.

 

I think I am following what you are doing here and I believe that you are really close to getting what you want. I don't see any effort to call the Make_DXF sub here, so are you running this code and then running the DXF code separately? I am pretty sure you could do this all in one shot but it will work this way too.

 

All you should need to do now is grab that custom iProperty value as the dxf code is building the file name. This can be tricky because you have to set up variables first. Here is what I recommend you try:

 

(note first - there are a number of iterations of the DXF code in this post, we might need to back up to the exact one you are using, but they are close enough that these steps are probably valid - also, the code I use today is improved/different from what is posted here, again we may need to get on the same page at some point here)

 

1. Dim all these variables at the top of the Make_DXF sub

	Dim oPropSets As PropertySets = doc.PropertySets
	Dim oSumInfo As PropertySet = oPropSets.Item("Inventor Summary Information")
	Dim oDocSumInfo As PropertySet = oPropSets.Item("Inventor Document Summary Information")
	Dim oDesTrackProps As PropertySet = oPropSets.Item("Design Tracking Properties")
	Dim oUserDefProps As PropertySet = oPropSets.Item("Inventor User Defined Properties")

(See bottom of this reply for what iProperties are found in what group of iProperties)

 

2.  Replace this line within Make_DXF sub:

       Dim New_Name As String = Part_Name 

with this line:

       Dim New_Name As String = oUserDefProps("StockSize").Value

 

In case you are wondering, yes, you only need the first and last Dim line in step 1, I just always Dim them all when I need to access iProperties and include the list (at the end of this reply) for future reference.

 

I have not tested any of this, hopefully it works without a hitch. Good luck and let me know if I can help further. @Aron.Molnar858QE 

 

-Kevin

 

List of iProperties Groups:

'''1) Inventor Summary Information
'''   1) Title
'''   2) Subject
'''   3) Author
'''   4) Keywords
'''   5) Comments
'''   6) Last Saved By
'''   7) Revision Number
'''   8) Thumbnail
'''2) Inventor Document Summary Information
'''   1) Category
'''   2) Manager
'''   3) Company
'''3) Design Tracking Properties
'''   1) Creation Time
'''   2) Part Number
'''   3) Project
'''   4) Cost Center
'''   5) Checked By
'''   6) Date Checked
'''   7) Engr Approved By
'''   8) Engr Date Approved
'''   9) User Status
'''   10) Material
'''   11) Part Property Revision Id
'''   12) Catalog Web Link
'''   13) Part Icon
'''   14) Description
'''   15) Vendor
'''   16) Document SubType
'''   17) Document SubType Name
'''   18) Proxy Refresh Date
'''   19) Mfg Approved By
'''   20) Mfg Date Approved
'''   21) Cost
'''   22) Standard
'''   23) Design Status
'''   24) Designer
'''   25) Engineer
'''   26) Authority
'''   27) Parameterized Template
'''   28) Template Row
'''   29) External Property Revision Id
'''   30) Standard Revision
'''   31) Manufacturer
'''   32) Standards Organization
'''   33) Language
'''   34) Defer Updates
'''   35) Size Designation
'''   36) Categories
'''   37) Stock Number
'''   38) Weld Material
'''   39) Mass
'''   40) SurfaceArea
'''   41) Volume
'''   42) Density
'''   43) Valid MassProps
'''   44) Flat Pattern Width
'''   45) Flat Pattern Length
'''   46) Flat Pattern Area
'''   47) Sheet Metal Rule
'''   48) Last Updated With
'''   49) Sheet Metal Width
'''   50) Sheet Metal Length
'''   51) Sheet Metal Area
'''   52) Material Identifier
'''   53) Appearance
'''   54) Flat Pattern Defer Update
'''4) Inventor User Defined Properties

 

0 Likes
Message 27 of 38

Ivan_Sinicyn
Advocate
Advocate

Hello.

Thank you very much for this code!

For my level, this is a very complex code, is it possible to make the curve of the external and all internal contours closed after exporting the DXF?

 

p.s. I found 

 

 

&MergeProfilesIntoPolyline=True

 

 

 

One more question. 

How to record the thickness of a part not from a sheet style, but from a list of parameters?

INV 2025.3
0 Likes
Message 28 of 38

kevinv
Enthusiast
Enthusiast

Hello Ivan,

 

I will answer your second question first. Yes, you can grab the parameter "Thickness" from your sheet metal rule and use it however you like. If I was building a dxf file name (like in my my example above) and wanted to add the material thickness I would add this line to my code after I created the variable New_Name and added the "StockSize" to it:

 

New_Name = New_Name & " " & doc.componentdefinition.parameters("Thickness").value & " Thick"

 One thing to know here - Even though my units are always inches when I access parameters like this it always returns the metric value, so I have to divide by 2.54 to get inches.

 

As far as your first question, I am sorry but I have no experience with closing curves of contours. I have also never tried to use ilogic to edit a dxf after it is created. My only dxf edits are rare and I use AutoCAD manually to do that. There is probably a way to do that with AutoCAD VBA, that is where I would start, but I am not sure. 

 

Good luck to you!

Message 29 of 38

Ivan_Sinicyn
Advocate
Advocate

Thank you.

I found the answer to the first question. It is necessary to add the following variable to the export line - "&MergeProfilesIntoPolyline=True"

And the contours of the curves will be closed.

 

oDataIO.WriteDataToFile("FLAT PATTERN DXF?AcadVersion=R12&RebaseGeometry=True&MergeProfilesIntoPolyline=True&SimplifySpline=True&InteriorProfilesLayer=IV_INTERIOR_PROFILES&InvisibleLayers=IV_TANGENT;IV_BEND;IV_BEND_DOWN;IV_TOOL_CENTER_DOWN;IV_ARC_CENTERS;IV_FEATURE_PROFILES;IV_FEATURE_PROFILES_DOWN;IV_UNCONSUMED_SKETCHES;IV_ROLL_TANGENT;IV_ROLL&SplineToleranceDouble=0.01",nameandpath)

 

INV 2025.3
Message 30 of 38

Kedar.Salvi
Community Visitor
Community Visitor

This code worked like crisp. Only thing it didn't do was import all the bend lines. What line of code needs to be updated so we can add bend lines to dxf.

0 Likes
Message 31 of 38

kevinv
Enthusiast
Enthusiast

Hi Kedar,

I am glad the code works for you! We do not use the bend lines on DXFs so I have never tried to include them.

If I did though I would focus on the line of code that starts with: 

oDataIO.WriteDataToFile(

Everything that follows on that line is the instructions of what to include and how to format the DXF files. There is a very good chance that a small change to that line of code will make it kick out the bend lines.

I hope that helps.

0 Likes
Message 32 of 38

WCrihfield
Mentor
Mentor

Hi @kevinv, & @Kedar.Salvi

I believe links below should help you out.  It documents the DataIO object, and its WriteDataToFile method.  They also list out all of the accepted variables you can put into that one long String, and explains some of them.

DataIO Object (Link1, Link2)

WriteDataToFile Method (Link1, Link2)

...I often include 2 links to the same thing, because there are 2 versions of the same website's URL.  Very frustrating when you area trying to post links to stuff a lot, because you never know which version will work for the other person.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 33 of 38

WCrihfield
Mentor
Mentor

Hi @Kedar.Salvi.  To help you with your last specific request about the bend lines...

I noticed in several of the examples posted on this thread, that they are including the available 'bend' layers in their 'InvisibleLayers' specifications (there are multiple possible layers for bend lines, and they are listed under the 'InvisibleLayers' part of their code).  If you are using their example, you may want to look closely where you see that 'InvisibleLayers' keyword, and delete any of those bend related layers from that list right after it.  Just an outside observation.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 34 of 38

J.J.Kucharczyk
Contributor
Contributor

THANK YOU!

It works as a dream. 

 

Can you tell me just where to change names of exported files to other format. 

 

I'm using as: 

 

[Thiskness] -(own text) - [FileName] - [Material] .dxf

 

 

Thnak you in advance 🙂 

0 Likes
Message 35 of 38

kevinv
Enthusiast
Enthusiast

Glad this was helpful! I apologize that I am not sure what you are asking. What other format? Are you trying to build a longer file name with all of those extra values like thickness? You can load whatever values you want into the variable Part_Name, that is what will come out as the file name. Let me know if I can help further @J.J.Kucharczyk 

Message 36 of 38

J.J.Kucharczyk
Contributor
Contributor

My mistake. I am not referring to the file format, DXF preferred. I am more concerned with the file name itself. As in the earlier example, I would like the file name to be like this:
[Thiskness] - [FileName] - [Material] .dxf

My modification:

 

173: 

		Part_Name = GA_Adder & " - stk"& " -  - "& Part_Name

 The file saves correctly, but the name contains:
[Material]-[Thiskness] ...

Skærmbillede 2023-08-07 083508.jpg

Is there any way to separate the material from the thickness in order to place them separately?

 

To get this filename as [Thiskness] - (own text)- [FileName] - [Material] .dxf

Skærmbillede 2023-08-07 083808.jpg

 

 

Thank you very much for any advice! 

0 Likes
Message 37 of 38

kevinv
Enthusiast
Enthusiast

Hello @J.J.Kucharczyk. If I understand correctly the value that you are trying to move to the end of the file name is the first part of the Sheet Metal Style coming from the part. That full value is being loaded into the GA_Adder variable here:

 

Dim GA_Adder As String = oSheetMetalCompDef.ActiveSheetMetalStyle.Name

 Short answer is yes, this can be done, but you will either need to play with the GA_Adder variable or find those values (already separated) from other Parameters or iProperties. For example, all of our Sheet Metal parts have a Parameter called "Thickness". I would set GA_Adder equal to that parameter and then when building the file name, I would also grab the Material name value from the part to add at the end of the file name.

 

If you want to play with the GA_Adder variable to get this done, you will need to find a logical way to break it up (as well as have some VB knowledge). Is the material value always 6 characters? Then GA_Adder = Left(GA_Adder, 6) would give you just the Material. Is the material always before the second dash? Then you could find the location of the second dash in the variable and grab the left or right of it. Playing with the variable is not ideal because whatever logic you use could be broken if you make changes to Inventor values later.

 

I hope this helps.

 

Message 38 of 38

J.J.Kucharczyk
Contributor
Contributor
Thank you very much 🙂 I managed to get this order in the automatic export in assembly, where I additionally add the number of pieces. However, the code for the name is written completely differently. That is why I got lost 🙂
Once again, many thanks. I will try to change the variables to arrange them in this order. I will let you know if I am successful.
0 Likes