Ilogic code, export all sheet metal as dxf in folder and write file name on dxf for graving

Ilogic code, export all sheet metal as dxf in folder and write file name on dxf for graving

sebastian_duerrenmatt2TK7V
Explorer Explorer
1,712 Views
23 Replies
Message 1 of 24

Ilogic code, export all sheet metal as dxf in folder and write file name on dxf for graving

sebastian_duerrenmatt2TK7V
Explorer
Explorer

Hi guys,

 

I`m searching desperatly for an Ilogic code to export dxf files from all sheet metal parts in an assembly. I`ve found some codes in the forum but i need in addition that the file name of the sheet metal part gets written on an edge of the dxf sheet metal unwinding. We`re chaning from Autodesk Advance to Inventor in our company.

 

Thanks a lot for your help!

 

In the attachment you`ll find an example from Advance how the exported dxf file should look like. There ist just the positionnumber but the whole file name would be better anyway.

0 Likes
Accepted solutions (1)
1,713 Views
23 Replies
Replies (23)
Message 2 of 24

contact
Advocate
Advocate

If you check for the DXF Exporter on the Autodesk App Store, this should help a lot.

 

They offer a trial, and the license is not expensive.

 

I use the DXF Exporter as well as the Tabs & Slots Tool. Very usefull.

 

The direct contact is here below:

 

Tools For Inventor | Micrographics Developed Inventor Apps

 

Best regards, Jan.

Message 3 of 24

marcin_otręba
Advisor
Advisor
Accepted solution

hi,

 

you can start from this one, but this is only exaple to start, i don;'t know your stadards ect. it uses part number property:

 

 

 

 

Dim ass As AssemblyDocument = ThisDoc.Document
On Error Resume Next
For Each ofile As Document In ass.AllReferencedDocuments
dxffilename = ""
If ofile.ComponentDefinition.Type = kSheetMetalComponentDefinitionObject Then
Dim oSheetMetalCompDef As SheetMetalComponentDefinition = ofile.ComponentDefinition
Dim fp As FlatPattern
If oSheetMetalCompDef.HasFlatPattern = False Then
oSheetMetalCompDef.Unfold
oSheetMetalCompDef.FlatPattern.ExitEdit
End If
fp = oSheetMetalCompDef.FlatPattern
nnname = ofile.PropertySets.Item(3).Item("Part Number").value

dxffilename = Replace(ofile.fullfilename, ".ipt", ".dxf")
fp.Edit()
Dim oSketch As PlanarSketch
Dim oSketches As PlanarSketches
Dim oTextBox As Inventor.TextBox
oSketches = fp.Sketches
Dim oFace As Face = fp.TopFace
Dim oTransGeom As TransientGeometry = ThisApplication.TransientGeometry

oSketch = oSketches.Add(oFace, False)
oTextBox = oSketch.TextBoxes.AddFitted(oTransGeom.CreatePoint2d(0.5, 1.2), nnname)
oTextBox.ConvertToGeometry("dim")
oSketch.ExitEdit()
Dim oDataIO As DataIO = ofile.ComponentDefinition.DataIO
Dim sOut As String       = "FLAT PATTERN DXF?AcadVersion=R12&SimplifySplines=true&FeatureProfilesUpLayerCOLOR=255;255;0&InvisibleLayers=IV_BEND;IV_BEND_DOWN;IV_TANGENT;IV_ARC_CENTERS;IV_FEATURE_PROFILES_DOWN;IV_TOOL_CENTER;IV_TOOL_CENTER_DOWN;IV_ROLL_TANGENT;IV_ALTREP_BACK;IV_ROLL;"
oDataIO.WriteDataToFile (sOut, dxffilename)
End If
Next

 

 

 

 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

Message 4 of 24

sebastian_duerrenmatt2TK7V
Explorer
Explorer

HI,

 

perfect, that was exactly what i was looking for. Thanks a lot for your help!

 

 

Best regards

Sebastian

0 Likes
Message 5 of 24

lechibaoduy1508
Explorer
Explorer

Hello, if i want to add the material and quanity beside the file name of the sheet metal part, how could i do? Thanks

0 Likes
Message 6 of 24

marcin_otręba
Advisor
Advisor

you can replace line 13 to :

nnname = ofile.PropertySets.Item(3).Item("Part Number").Value & "  " & ofile.ActiveMaterial.DisplayName & "   " & ass.ComponentDefinition.Occurrences.AllReferencedOccurrences(ofile)

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 7 of 24

lechibaoduy1508
Explorer
Explorer

lechibaoduy1508_0-1737422024354.png

I try it, but how can i fix it, Thanks !

0 Likes
Message 8 of 24

Manuel_Coca
Advocate
Advocate

Muchas gracias por compartir este datos, es lo que estaba buscando.

0 Likes
Message 9 of 24

marcin_otręba
Advisor
Advisor

sorry, it should be 

nnname = ofile.PropertySets.Item(3).Item("Part Number").Value & "  " & ofile.ActiveMaterial.DisplayName & "   " & ass.ComponentDefinition.Occurrences.AllReferencedOccurrences(ofile).Count

 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 10 of 24

rzsla
Contributor
Contributor

Hello, I am using a code almost similar to this. The problem I am facing is, when I enter the FlatPattern Edit. Inventor takes the longest edge and puts it along the X-axis. But, Sometimes, the perpendicular side of the edge is in negative Y-axis. Hence, the value otg.createpoint2d(1.1,1) is etching part numbers in space that doesn't show on the part irl.  I only want help with the textbox location. i.e grabbing the edge that lies on the X-axis (longest edge in this case) and making sure the Y-value is inside the part. Be it +ve or -ve y-axis. 

Also, it is crucial that I do not change the orientation of the flat pattern. (I can not make all -ve y-axis parts +ve) 

 

Edit: I am attaching pictures and code for you to see.

 

Dim oPDoc As PartDocument = ThisDoc.Document
Dim oCompDef As PartComponentDefinition = oPDoc.ComponentDefinition
Dim oCompDefSM As SheetMetalComponentDefinition = oPDoc.ComponentDefinition
If oCompDefSM.HasFlatPattern Then
	oCompDef.Unfold
	' Access the flat pattern
	Dim oFlatPattern As FlatPattern = oCompDefSM.FlatPattern
	'Dim aSideFace As Inventor.ASideDefinition = oCompDef.ASideDefinitions(1)
	' Create a new sketch on the flat pattern
	Dim oSketch As PlanarSketch = oFlatPattern.Sketches.Add(oFlatPattern.TopFace, True)

	' Define the text position at (0, 0)
	Dim oTextPosition As Point2d = ThisServer.TransientGeometry.CreatePoint2d(0, 0)

	' Add text to the sketch
	Dim oTextBox As Inventor.TextBox = oSketch.TextBoxes.AddFitted(oTextPosition, "Part Number")

	' Activate the flat pattern view
	MsgBox("Text added to the flat pattern at (0,0).")
Else
	MsgBox("No flat pattern exists in the current document.")
End If

 

rzsla_0-1737533031051.png

 

0 Likes
Message 11 of 24

lechibaoduy1508
Explorer
Explorer

I've got it. Thanks for your support!

 

0 Likes
Message 12 of 24

marcin_otręba
Advisor
Advisor

hi,

 

you can try:

 

 If oSketch.NaturalAxisDirection = True Then
    oTextBox = oSketch.TextBoxes.AddFitted(oTransGeom.CreatePoint2d(0.5, 1.2),  nnname)
 End If
 If oSketch.NaturalAxisDirection = False Then
    oTextBox = oSketch.TextBoxes.AddFitted(oTransGeom.CreatePoint2d(0.5 + 6.4, -1.2), nnname)
    oTextBox.Rotation = 4 * Math.Atan(1)
End If

 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

Message 13 of 24

lechibaoduy1508
Explorer
Explorer

lechibaoduy1508_0-1737604915188.pnglechibaoduy1508_1-1737604925233.png

Hello, i try this code but i want to show bending line like this, how could i do? Thanks. 
Have a nice day!

 

0 Likes
Message 14 of 24

marcin_otręba
Advisor
Advisor

just make changes in line 29 where you define wchich layers are invisible:

 

Dim sOut As String       = "FLAT PATTERN DXF?AcadVersion=R12&SimplifySplines=true&FeatureProfilesUpLayerCOLOR=255;255;0&InvisibleLayers=IV_BEND;IV_BEND_DOWN;IV_TANGENT;IV_ARC_CENTERS;IV_FEATURE_PROFILES_DOWN;IV_TOOL_CENTER;IV_TOOL_CENTER_DOWN;IV_ROLL_TANGENT;IV_ALTREP_BACK;IV_ROLL;"

 

change it to:

 

Dim sOut As String       = "FLAT PATTERN DXF?AcadVersion=R12&SimplifySplines=true&FeatureProfilesUpLayerCOLOR=255;255;0&InvisibleLayers=IV_TANGENT;IV_ARC_CENTERS;IV_FEATURE_PROFILES_DOWN;IV_TOOL_CENTER;IV_TOOL_CENTER_DOWN;IV_ROLL_TANGENT;IV_ALTREP_BACK;IV_ROLL;"

 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 15 of 24

lechibaoduy1508
Explorer
Explorer

That was exactly what i was looking for. Thanks a lot for your help!
Have a nice day!

0 Likes
Message 16 of 24

rzsla
Contributor
Contributor

That works beautifully, I searched all over the Api help to look for something like natural axis but was unable to do so. Do you mind sharing how you came about to knowing its existence. So that, I can continue to learn and grow.

 

Thank you once again. 

 

0 Likes
Message 17 of 24

marcin_otręba
Advisor
Advisor

normally when i am looking for something i go to object i am interrested in:

for example when i would like to check possibilities regarding sketch i go into planarsketch object because :

 

Dim oSketch As PlanarSketch

Inventor 2025 Help | PlanarSketchProxy Object | Autodesk

 

and i am studying all methods and properties wchich are available in that object, for example NaturalAxisDirection:

 

Inventor 2025 Help | PlanarSketchProxy.NaturalAxisDirection Property | Autodesk

 

i do not know why there are no result for neutral axis keywords, because you will find it when uyou type neutralaxisdirection for sure.

 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

Message 18 of 24

rzsla
Contributor
Contributor

Thank you for taking the time to reply. I have come across a really difficult situation from the last time we were here.

I have managed to add the textbox according to the rule you suggested. but there are some pesky parts that require the textbox to have some sort of feature detection. For example: 

rzsla_0-1738309100105.png

 in this part We would like to ensure the part number does not go off the edge of the hole which will make the etching useless. And, in next part 

 

rzsla_1-1738309217904.png

 

We would have to avoid the part number touching the slots. Lastly, 

 

 

rzsla_2-1738309250539.png

 

in this, We have to make sure that the part number to be etched does not interfere with the previous etching. The old etching was done using extrude cut feature not the mark feature like I will be using for all the part numbers. 

 

 I was thinking maybe we could use edgeloops and edgeuse in some manner. But I have never worked with them nor am I too experienced with ilogic. Any kind of help would be appreciated. I am posting my code below; There are some unnecessary lines that help me visualize. so, feel free to comment them out. 

 

Dim asmDoc As AssemblyDocument = ThisDoc.Document
Dim asmDef As AssemblyComponentDefinition = asmDoc.ComponentDefinition
Dim oTransGeom As TransientGeometry = ThisServer.TransientGeometry


For Each oDoc As Document In asmDoc.AllReferencedDocuments
	If oDoc.DocumentType = kPartDocumentObject Then
		Dim oPDoc As PartDocument = oDoc
		Dim oCompDef As PartComponentDefinition = oPDoc.ComponentDefinition
		oDocName = oPDoc.DisplayName
			
Dim oCompDefSM As SheetMetalComponentDefinition = oPDoc.ComponentDefinition If oCompDefSM.HasFlatPattern Then oCompDefSM.FlatPattern.Delete() End If oCompDef.Unfold Dim oFlatPattern As FlatPattern = oCompDefSM.FlatPattern Dim natural As Boolean Dim osketch2 As PlanarSketch = oFlatPattern.Sketches.Add(oFlatPattern.TopFace) If osketch2.NaturalAxisDirection = True Then natural = True Else natural = False End If For Each oSketch1 As Sketch In oFlatPattern.Sketches oSketch1.Delete Next Dim oSketch As PlanarSketch = oFlatPattern.Sketches.AddWithOrientation(oFlatPattern.TopFace, oCompDef.WorkAxes.Item(1), True, True, oCompDef.WorkPoints.Item(1)) Dim oTextPosition As Point2d Dim oTextBox As Inventor.TextBox Dim oBox As Box = oFlatPattern.RangeBox Dim minPoint As Point = oBox.MinPoint Dim maxPoint As Point = oBox.MaxPoint Dim minPointX As Double = minPoint.X Dim maxPointY As Double = maxPoint.Y closestpoint = oFlatPattern.TopFace.GetClosestPointTo(minPoint) xminymax = oTransGeom.CreatePoint(minPoint.X, maxPoint.Y, 0) closestpoint2 = oFlatPattern.TopFace.GetClosestPointTo(xminymax) If natural = True Then oTextPosition = oTransGeom.CreatePoint2d(closestpoint.X + 1, closestpoint.Y + 1) oTextBox = oSketch.TextBoxes.AddFitted(oTextPosition, "Part Number") If oBox.Contains(oSketch.SketchToModelSpace(oTextBox.Origin)) Then ' MessageBox.Show("Textbox is Inside the flatpattern") Else MessageBox.Show("Textbox is Outside the flatpattern") oTextPosition = oTransGeom.CreatePoint2d(closestpoint.X, closestpoint.Y) End If Else oTextPosition = oTransGeom.CreatePoint2d(closestpoint2.X + 1, closestpoint2.Y - 1) oTextBox = oSketch.TextBoxes.AddFitted(oTextPosition, "<Part Number>") ' otextbox.Rotation = 4 * Math.Atan(1) End If oTextBox.FormattedText = oPDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value ' Helps to visualize the bounding box '[
minPoint = oBox.MinPoint maxPoint = oBox.MaxPoint Dim point1 As Point2d = oTransGeom.CreatePoint2d(minPoint.X, minPoint.Y) Dim point2 As Point2d = oTransGeom.CreatePoint2d(minPoint.X, maxPoint.Y) Dim point3 As Point2d = oTransGeom.CreatePoint2d(maxPoint.X, maxPoint.Y) Dim point4 As Point2d = oTransGeom.CreatePoint2d(maxPoint.X, minPoint.Y) Dim oLines1 As SketchLine Dim oLines2 As SketchLine Dim oLines3 As SketchLine Dim oLines4 As SketchLine oLines1 = oSketch.SketchLines.AddByTwoPoints(point1, point2) ' Left vertical line oLines2 = oSketch.SketchLines.AddByTwoPoints(point2, point3) ' Top horizontal line oLines3 = oSketch.SketchLines.AddByTwoPoints(point3, point4) ' Right vertical line oLines4 = oSketch.SketchLines.AddByTwoPoints(point4, point1) ' Bottom horizontal line ]' End If End If Next

 

0 Likes
Message 19 of 24

C_Haines_ENG
Collaborator
Collaborator

Can you attach an example part file that I can use? Tough cookie of a problem. 

0 Likes
Message 20 of 24

frank5838S
Contributor
Contributor

Hi,

 

I'm trying to get this to work but I'm fairly new with iLogic.

I have an assembly including multiple sheet metal parts and need the dxf files for cutting the parts.

I Tried to add this as a new iLogic rule in my main assembly this but no result.

Can you provide some beginner advise how to get this to work?

How to select a destination folder?

 

With my previous job we had a dxf exporter installed as a botton in the ribbon and you could select a destination folder, Autocad would then open and a position number was placed inside the dxf.

I miss that tool now in my new job and trying to find a dxf exporter with much of the same functions as this will save a lot of work.

 

Thanks in advance.

 

Frank

0 Likes