Export a DXF of every model state for a part?

Export a DXF of every model state for a part?

claudio.ibarra
Advocate Advocate
850 Views
6 Replies
Message 1 of 7

Export a DXF of every model state for a part?

claudio.ibarra
Advocate
Advocate

I have a part for a label that's going on an engraver. It contains 3 lines of text. I'm using model states to generate every version of the label, and I want to make a DXF for each to give to the engraver operator.

Is it possible for an iLogic rule in a drawing to look at associated .ipt, iterate through each model state and create a DXF for each one? 

0 Likes
Accepted solutions (1)
851 Views
6 Replies
Replies (6)
Message 2 of 7

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

Hello. I hope the following code will help you.

 

Sub Main
    Dim oDoc As Document = ThisApplication.ActiveDocument
	If TypeOf oDoc Is PartDocument Then
		Dim oPartDoc As PartDocument = oDoc
		Dim sActiveMS As String = oPartDoc.ModelStateName
		If TypeOf oPartDoc.ComponentDefinition Is SheetMetalComponentDefinition Then
			Dim oPartDef As SheetMetalComponentDefinition = oPartDoc.ComponentDefinition
			Dim sDirectName As String = System.IO.Path.GetDirectoryName(oDoc.FullDocumentName)
			Dim sNameDoc As String = System.IO.Path.GetFileNameWithoutExtension(oDoc.FullDocumentName)
			Dim sNameAndPath As String = sDirectName & "\" & sNameDoc & ".dxf"
			'[Seting export DXF
			Dim sSetDXF As String = "FLAT PATTERN DXF?AcadVersion=R12&RebaseGeometry=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"
'			Dim sSetDXF As String = "FLAT PATTERN DXF?AcadVersion=2004&OuterProfileLayer=IV_OUTER_PROFILE"
			']
			For Each oMS As ModelState In oPartDef.ModelStates
				oMS.Activate()			
				sNameAndPath = sDirectName & "\" & sNameDoc & " (" & oMS.Name & ")" & ".dxf"
				Dim oDataIO As DataIO = oPartDef.DataIO			
				Call oDataIO.WriteDataToFile(sSetDXF, sNameAndPath)
			Next
			oPartDef.ModelStates.Item(sActiveMS).Activate()
		Else
			MessageBox.Show("Active document is not SheetMetalDocument!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
		End If
	Else
		MessageBox.Show("Active document is not PartDocument!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
	End If    
End Sub

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

Message 3 of 7

claudio.ibarra
Advocate
Advocate

That worked, thank you! 

 

I thought DXFs had to be made from a drawing, and I hadn't considered making it a sheet metal part.

0 Likes
Message 4 of 7

diego_dorta
Enthusiast
Enthusiast

great rule thanks

 

is it possible to use the part number of each model state as dxf file name?

 

I think this is the string to modify:

sNameAndPath = sDirectName & "\" & sNameDoc & " (" & oMS.Name & ")" & ".dxf"

 

but I can't find the way to catch the part number of the model state.

 

thank you

0 Likes
Message 5 of 7

Andrii_Humeniuk
Advisor
Advisor

Hi @diego_dorta . Try this code:

Sub Main
    Dim oDoc As Document = ThisApplication.ActiveDocument
	If TypeOf oDoc Is PartDocument Then
		Dim oPartDoc As PartDocument = oDoc
		Dim sActiveMS As String = oPartDoc.ModelStateName
		If TypeOf oPartDoc.ComponentDefinition Is SheetMetalComponentDefinition Then
			Dim oPartDef As SheetMetalComponentDefinition = oPartDoc.ComponentDefinition
			Dim sDirectName As String = System.IO.Path.GetDirectoryName(oDoc.FullDocumentName)
			Dim sNameDoc As String = System.IO.Path.GetFileNameWithoutExtension(oDoc.FullDocumentName)
			Dim sPartNumb, sNameAndPath As String
			'[Seting export DXF
			Dim sSetDXF As String = "FLAT PATTERN DXF?AcadVersion=R12&RebaseGeometry=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"
'			Dim sSetDXF As String = "FLAT PATTERN DXF?AcadVersion=2004&OuterProfileLayer=IV_OUTER_PROFILE"
			']
			For Each oMS As ModelState In oPartDef.ModelStates
				oMS.Activate()
				sPartNumb = oPartDoc.PropertySets("Design Tracking Properties")("Part Number").Value
				sNameAndPath = sDirectName & "\" & sPartNumb & ".dxf"
				Dim oDataIO As DataIO = oPartDef.DataIO			
				Call oDataIO.WriteDataToFile(sSetDXF, sNameAndPath)
			Next
			oPartDef.ModelStates.Item(sActiveMS).Activate()
		Else
			MessageBox.Show("Active document is not SheetMetalDocument!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
		End If
	Else
		MessageBox.Show("Active document is not PartDocument!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
	End If    
End Sub

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

Message 6 of 7

diego_dorta
Enthusiast
Enthusiast

super

exactly what I was looking for!!

 

thank you very much

0 Likes
Message 7 of 7

Jordon.Oldham
Participant
Participant
hi there!

sorry to tag onto this thread, but i am trying to do the same thing as above but none of the rules work for me.
I have several parts that each contain several that id like to auto export with their part codes as their file name.

any help will be greatly appreciated.

Jordon
0 Likes