DXF Export with ilogic and save as location.

DXF Export with ilogic and save as location.

davis.j
Advocate Advocate
1,545 Views
4 Replies
Message 1 of 5

DXF Export with ilogic and save as location.

davis.j
Advocate
Advocate

Can someone help me modify this code?

 

I am looking to use the standard behavior where it asks you where to save the DXF rather then a specified folder.

 

The code slightly changed to suit some of my needs but is near identical to this thread:

https://forums.autodesk.com/t5/inventor-customization/modify-layers-before-exporting-dxf-file-using-...

 

oDoc = ThisDoc.Document

	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?OuterProfileLayer=0&OuterProfileLayerColor=0;0;0&InteriorProfilesLayer=0&InteriorProfilesLayerColor=0;0;0&BendDownLayerLineType=37633&BendDownLayerColor=0;0;255&BendUpLayerLineType=37633&BendUpLayerColor=0;0;255IV_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" _
		+ "&RebaseGeometry=True" _
		+ "&SimplifySplines=True" _
		+ "&SplineTolerance=0.01" _
		
	sFname = oPath & "\"& "myFile.dxf"
	oCompDef.DataIO.WriteDataToFile(sOut, sFname)
	Dim oSMDef As SheetMetalComponentDefinition
	oSMDef = oDoc.ComponentDefinition
	oSMDef.FlatPattern.ExitEdit
	
	MessageBox.Show("Your file was saved in the following dirctory: " + sFname)
	Else
		MessageBox.Show("Only sheet metal parts can be exported as DXF.")
	End If

 

I like to pick from my preset folders to select the save location. I also manually type in revision suffix's in the name of the file sometimes.

 

Is this possible?

 

0 Likes
1,546 Views
4 Replies
Replies (4)
Message 2 of 5

Mike.Wohletz
Collaborator
Collaborator

I think you are looking to do something like this? 

 

oDoc = ThisDoc.Document

	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
	

Dim sfd As New SaveFileDialog
sfd.Filter = "DXF Files (*.dxf*)|*dxf"
sfd.InitialDirectory = oPath

If sfd.ShowDialog = System.Windows.Forms.DialogResult.OK Then
	sFname = sfd.FileName
	Else
		sFname = oPath & "\"& "myFile.dxf"
	End If
	

	

	sOut = "FLAT PATTERN DXF?OuterProfileLayer=0&OuterProfileLayerColor=0;0;0&InteriorProfilesLayer=0&InteriorProfilesLayerColor=0;0;0&BendDownLayerLineType=37633&BendDownLayerColor=0;0;255&BendUpLayerLineType=37633&BendUpLayerColor=0;0;255IV_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" _
		+ "&RebaseGeometry=True" _
		+ "&SimplifySplines=True" _
		+ "&SplineTolerance=0.01" _
		
	
	oCompDef.DataIO.WriteDataToFile(sOut, sFname)
	Dim oSMDef As SheetMetalComponentDefinition
	oSMDef = oDoc.ComponentDefinition
	oSMDef.FlatPattern.ExitEdit
	
	MessageBox.Show("Your file was saved in the following directory: " + sFname)
	Else
		MessageBox.Show("Only sheet metal parts can be exported as DXF.")
	End If
Message 3 of 5

davis.j
Advocate
Advocate

Yes, Thank you for your expertise. I have taken your codes and edited it further as it was still doing some funky folder shenanigan's that I had in there. Can you test this new code below and see if there is any issues for you?

The end goal of this illogic is to spit out a DXF while being able to select where to save it and specific the layers and other options. I will have to additionally open these DXF's with AutoCAD and make some other small edits as per the design intent but this will save me lots of time.

 

My other method involves opening the flat pattern in a drawing sheet and setting the bend up and then doing a save copy as. There is much more steps in my old method. Also the old method doesn't allow you to set the spline simplification and tolerance. I mainly am using that feature to cope with bad geometry or parts that for some reason include splines instead of polylines, lines and arc. Also sometimes with the splines in the bad geometry with the other DXF exports methods that do no come out as splines but rather a BAZILLION line entities which causes errors and machine malfunctions in production.

 

For parts without bends I usually right click on the face of the part and select "Export Face as..."

 

Do you know if there is any redundant or conflicting statements in the code? I will be testing this some more to see if any issues happen before I use this as a standard rule.

 

 

oDoc = ThisDoc.Document
 
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
 
	If Not System.IO.Directory.Exists(oPath) Then
		System.IO.Directory.CreateDirectory(oPath)
	End If
 
	Dim sFname As String
 
	Dim sfd As New SaveFileDialog
		sfd.Filter = "DXF Files (*.dxf*)|*dxf"
		sfd.InitialDirectory = oPath
		sfd.FileName = iProperties.Value("Project", "Part Number")& ".dxf"
 
	If sfd.ShowDialog = System.Windows.Forms.DialogResult.OK Then
		sFname = sfd.FileName
	Else
		sFname = oPath & "\"& ".dxf"
	End If
 
 
	sOut = "FLAT PATTERN DXF?OuterProfileLayer=0&OuterProfileLayerColor=0;0;0&InteriorProfilesLayer=0&InteriorProfilesLayerColor=0;0;0&BendDownLayerLineType=37633&BendDownLayerColor=0;0;255&BendUpLayerLineType=37633&BendUpLayerColor=0;0;255IV_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" _
		+ "&RebaseGeometry=True" _
		+ "&SimplifySplines=True" _
		+ "&SplineTolerance=0.01" _
 
 
	oCompDef.DataIO.WriteDataToFile(sOut, sFname)
	Dim oSMDef As SheetMetalComponentDefinition
	oSMDef = oDoc.ComponentDefinition
	oSMDef.FlatPattern.ExitEdit
 
	MessageBox.Show("Your file was saved in the following directory: " + sFname)
Else
	MessageBox.Show("Only sheet metal parts can be exported as DXF.")
End If

 

 

0 Likes
Message 4 of 5

davis.j
Advocate
Advocate

The code above works but only If I don't edit the filename when saving.

 

I like how it asks where you want to save the file but I cant change the filename. If I change the file name in the prompt the file gets created but comes out as a file with no extension. Then I have to add .dxf to the end.

 

I'd like to initially pull the part number but occasionally I have to make edits to the dxf filename. Examples:

  • "PART_NUMBER" -Rev2
  • "PART_NUMBER" -Laser
  • "PART_NUMBER"  test

I'm not sure exactly where I am going wrong.

0 Likes
Message 5 of 5

Ralf_Krieg
Advisor
Advisor

Hello

 

Check if extension exist in filename and if not, add it. There may be a smarter way, but it works so far.

 

oDoc = ThisDoc.Document
 
If oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
 
	Dim oCompDef As SheetMetalComponentDefinition = oDoc.ComponentDefinition
 
	If oCompDef.HasFlatPattern = False Then
		oCompDef.Unfold
	Else
		oCompDef.FlatPattern.Edit
	End If
 
	Dim sOut As String ="FLAT PATTERN DXF?OuterProfileLayer=0&OuterProfileLayerColor=0;0;0&InteriorProfilesLayer=0&InteriorProfilesLayerColor=0;0;0&BendDownLayerLineType=37633&BendDownLayerColor=0;0;255&BendUpLayerLineType=37633&BendUpLayerColor=0;0;255IV_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" _
		+ "&RebaseGeometry=True" _
		+ "&SimplifySplines=True" _
		+ "&SplineTolerance=0.01" _

	Dim oPath As String = ThisDoc.Path

	' makes no sense cause oPath is path of the current document
	' it either exist or is empty in case the document is not saved until now
	'If Not System.IO.Directory.Exists(oPath) Then
	'	System.IO.Directory.CreateDirectory(oPath)
	'End If

	If oPath = String.Empty Then
		MsgBox("Please save your document first.", , "iLogic Export Flat Pattern")
		Exit Sub
	End If
		
	Dim sFname As String
	Dim sfd As New SaveFileDialog
	
	sfd.Filter = "DXF Files (*.dxf)|*dxf"
	sfd.InitialDirectory = oPath
	sfd.FileName = iProperties.Value("Project", "Part Number")
 
	If sfd.ShowDialog = System.Windows.Forms.DialogResult.OK Then
		sFname = sfd.FileName
		If Not Strings.Right(sFname, 4) = ".dxf" Then sFname = sFname & ".dxf"
	Else
		'User canceled out dialog
		Exit Sub
	End If
 	
 	oCompDef.DataIO.WriteDataToFile(sOut, sFname)
	oCompDef.FlatPattern.ExitEdit
 
	MessageBox.Show("Your file was saved in the following directory: " + sFname)
Else
	MessageBox.Show("Only sheet metal parts can be exported as DXF.")
End If

 


R. Krieg
RKW Solutions
www.rkw-solutions.com