Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Export .dxf file with file name built from custom iProperties in the .ipt

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
shawn.budden
1580 Views, 9 Replies

Export .dxf file with file name built from custom iProperties in the .ipt

I'm working on a code that will export .dxf files from an assembly for every sheet metal part. Everything works except creating the .dxf file name from custom iProperties that reside in each part.  What is the best method of referencing the custom iProperties so that they may be used to create the file name of the .dxf?

Labels (3)
9 REPLIES 9
Message 2 of 10
WCrihfield
in reply to: shawn.budden

Similar to this:

 

 

 

 

 

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
	MsgBox("An Assembly Document must be active for this rule (" & iLogicVb.RuleName & ") to work. Exiting.",vbOKOnly+vbCritical, "WRONG DOCUMENT TYPE")
	Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisAssembly.Document

'where to save all the DXF's to
Dim oFolder As String = "C:\Temp\DXFs\"

Dim oRefDoc As Document
Dim oPDoc As PartDocument
Dim oPath, oName, oDxfName As String
Dim oCProps As Inventor.PropertySet
For Each oRefDoc In oADoc.AllReferencedDocuments
	If oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
		oPDoc = ThisApplication.Documents.Open(oRefDoc.FullDocumentName, False)
		If oPDoc.PropertySets.Item("Design Tracking Properties").Item("Document SubType Name").Value = "Sheet Metal" Then
			'it is a Sheet Metal Part
			oPath = IO.Path.GetDirectoryName(oPDoc.FullFileName)
			oName = IO.Path.GetFileNameWithoutExtension(oPDoc.FullFileName)

			'here is your 'Custom' iProperties set
			oCProps = oPDoc.PropertySets.Item("Inventor User Defined Properties")
			'assemble your DXF file name here
			Dim oCProp1 As String = oCProps.Item("PropertyName").Value
			Dim oCProp2 As String = oCProps.Item("OtherPropertyName").Value
			
			oDxfName = oFolder & oName & " " & oCProp1 & " " & oCProp2 & ".dxf"
			
			'Then export it here.

		End If
	End If
	oPDoc.Close(True)
Next

 

 

 

 

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE' 👍.

If you have time, please... Vote For My IDEAS :light_bulb:or you can Explore My CONTRIBUTIONS

Inventor 2021 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 10
shawn.budden
in reply to: WCrihfield

Thanks a lot for responding.  I'm pretty sure that you understand what I am trying to do.  I modified your code a bit and tried it, but it fails when I try to unfold the sheet metal part.  Any idea where I'm going astray?

 

'Check that the active document is an assembly file
Dim oADoc As AssemblyDocument
oADoc = ThisApplication.ActiveDocument

If oADoc.DocumentType <> kAssemblyDocumentObject Then
	MessageBox.Show("Please run this rule from the assembly file.", "iLogic")
	Exit Sub
End If

'Get user input
RUsure = MessageBox.Show ( _
"This will create a DXF file for all of the asembly components that are sheet metal." _
& vbLf & "This rule expects that the part file is saved." _
& vbLf & " " _
& vbLf & "Are you sure you want to create DXF for all of the assembly components?" _
& vbLf & "This could take a while.", "iLogic  - Batch Output DXFs ", MessageBoxButtons.YesNo)

If RUsure <> vbYes Then Exit Sub

'where to save all the DXF's to
Dim oFolder As String = "H:\Detailing\Inventor\DXF_FILES\DXFs\"

'Check for the DXF folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then
    System.IO.Directory.CreateDirectory(oFolder)
End If

Dim oRefDoc As Document
Dim oPDoc As PartDocument
Dim oPath, oName, oDxfName As String
Dim oCProps As Inventor.PropertySet
For Each oRefDoc In oADoc.AllReferencedDocuments
	If oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
		oPDoc = oRefDoc
		If oPDoc.PropertySets.Item("Design Tracking Properties").Item("Document SubType Name").Value = "Sheet Metal" Then
			'it is a Sheet Metal Part, now check to see if it has a drawing document
			'get its full path and file name, without the extension
			oPath = IO.Path.GetDirectoryName(oPDoc.FullFileName)
			oName = IO.Path.GetFileNameWithoutExtension(oPDoc.FullFileName)

			'here is your 'Custom' iProperties set
			oCProps = oPDoc.PropertySets.Item("Inventor User Defined Properties")
			
			'assemble your DXF file name here
			Dim oCProp1 As String = oCProps.Item("JOB_NUMBER").Value
			Dim oCProp2 As String = oCProps.Item("NESTING_DIGIT").Value
			Dim oCProp3 As String = oCProps.Item("MARK").Value
			
			oDxfName = oFolder & oName & oCProp1 & oCProp2 & oCProp3 & ".dxf"
			
			'Then export it here.
If oPDoc.HasFlatPattern = False Then
	Try 
	'create flat pattern
		oPDoc.Unfold 
	Catch
	Return 'exit rule
	End Try
	Else 'if flat pattern exists
		Try
			'edit flat pattern
			oPDoc.FlatPattern.Edit 
		Catch
			Return 'exit rule
		End Try
	End If
			

	Dim sOut As String = "FLAT PATTERN DXF?AcadVersion=2000&OuterProfileLayer=Outer&CustomizeFilename=H:\Detailing\Inventor\DESIGN_DATA\Design Data\DWG-DXF\FlatPattern.xml"
		
		oPDoc.DataIO.WriteDataToFile(sOut, oFolder & "\" & oDxfName)
		oPDoc.FlatPattern.ExitEdit()
	
		End If
	End If
	oPDoc.Close(True)
Next
Message 4 of 10
WCrihfield
in reply to: shawn.budden

I noticed that oDxfName contains oFolder, then at the end, in your DataIO out line, you are including oFolder in it again.  This seems like a mistake to me, you should check that.

I included the SheetMetalComponentDefinition.  That's where you can access stuff unique to sheet metal parts through, like the FlatPattern.

And I believe you were attempting to export the FlatPattern itself, not the whole part document to DXF, so I changed the reference in your DataIO out line.

You don't need to put the FlatPattern in edit mode to export it.

Give this a try:

'Check that the active document is an assembly file
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
	MessageBox.Show("Please run this rule from the assembly file.", "iLogic")
	Exit Sub
End If
Dim oADoc As AssemblyDocument
oADoc = ThisApplication.ActiveDocument

'Get user input
RUsure = MessageBox.Show ( _
"This will create a DXF file for all of the asembly components that are sheet metal." _
& vbLf & "This rule expects that the part file is saved." _
& vbLf & " " _
& vbLf & "Are you sure you want to create DXF for all of the assembly components?" _
& vbLf & "This could take a while.", "iLogic  - Batch Output DXFs ", MessageBoxButtons.YesNo)

If RUsure <> vbYes Then Exit Sub

'where to save all the DXF's to
Dim oFolder As String = "H:\Detailing\Inventor\DXF_FILES\DXFs\"

'Check for the DXF folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then
    System.IO.Directory.CreateDirectory(oFolder)
End If

Dim oRefDoc As Document
Dim oPath, oName, oDxfName As String

For Each oRefDoc In oADoc.AllReferencedDocuments
	If oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
		Dim oPDoc As PartDocument = ThisApplication.Documents.Open(oRefDoc.FullDocumentName, False)
		If oPDoc.PropertySets.Item("Design Tracking Properties").Item("Document SubType Name").Value = "Sheet Metal" Then
			Dim oSMDef As SheetMetalComponentDefinition = oPDoc.ComponentDefinition
			oName = IO.Path.GetFileNameWithoutExtension(oPDoc.FullFileName)

			'here is your 'Custom' iProperties set
			Dim oCProps As Inventor.PropertySet = oPDoc.PropertySets.Item("Inventor User Defined Properties")
			
			'assemble your DXF file name here
			Dim oCProp1 As String = oCProps.Item("JOB_NUMBER").Value
			Dim oCProp2 As String = oCProps.Item("NESTING_DIGIT").Value
			Dim oCProp3 As String = oCProps.Item("MARK").Value
			
			oDxfName = oFolder & oName & oCProp1 & oCProp2 & oCProp3 & ".dxf"
			
			Dim oFPattern As FlatPattern
			If oSMDef.HasFlatPattern = False Then
				Try
					'create flat pattern
					oSMDef.Unfold
					oFPattern = oSMDef.FlatPattern
				Catch
					'don't exit rule, just skip to the next loop document
					MsgBox("Failed to 'Unfold' " & oPDoc.FullFileName & vbCrLf & _
					"Skipping it and continuing to the next document.", , "")
					Continue For
				End Try
			Else 'if flat pattern exists
				oFPattern = oSMDef.FlatPattern
			End If
						
			Dim sOut As String = "FLAT PATTERN DXF?AcadVersion=2000&OuterProfileLayer=Outer&CustomizeFilename=H:\Detailing\Inventor\DESIGN_DATA\Design Data\DWG-DXF\FlatPattern.xml"
					
			oFPattern.DataIO.WriteDataToFile(sOut, oFolder & "\" & oDxfName)
	
		End If
		oPDoc.Close(True)
	End If
Next

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE' 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 10
shawn.budden
in reply to: shawn.budden

Thank you very much.  Taking out the extra ofolder reference, adding the SheetMetalComponentDefinition, and exporting the whole part to DXF made the difference.  And thank you for pointing out that you do not need to be in the edit mode to export the flat pattern.

 

Again, I really appreciate it.  Thanks for sharing.

 

Message 6 of 10
car_quezada
in reply to: shawn.budden

Hi, I tried to use your code with the same intencion but I dont be able to make it work :c 
I need the same, Export platpaterns DXF files with a custom Parameters in the name, but for some reason, te code just make the folder but nothing more, Im pretty new with ilogic so probably is something small in the code, but I need help for sure. 

 

This is the code Im using (As an external rule):

 

 

'Sub Main()
 
'Check that the active document is an assembly file
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
MessageBox.Show("Please run this rule from the assembly file.", "iLogic")
Exit Sub
End If
Dim oADoc As AssemblyDocument
oADoc = ThisApplication.ActiveDocument
 
'Get user input
RUsure = MessageBox.Show ( _
"This will create a DXF file for all of the asembly components that are sheet metal." _
& vbLf & "This rule expects that the part file is saved." _
& vbLf & " " _
& vbLf & "Are you sure you want to create DXF for all of the assembly components?" _
& vbLf & "This could take a while.", "iLogic  - Batch Output DXFs ", MessageBoxButtons.YesNo)
 
If RUsure <> vbYes Then Exit Sub
 
'where to save all the DXF's to
Dim oFolder As String = "C:\Users\SROSS\Documents\Directorio Exportacion Temporal DXF Ilogic\TEST\"
 
'Check for the DXF folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then
    System.IO.Directory.CreateDirectory(oFolder)
End If
 
Dim oRefDoc As Document
Dim oPath, oName, oDxfName As String
 
For Each oRefDoc In oADoc.AllReferencedDocuments
If oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
Dim oPDoc As PartDocument = ThisApplication.Documents.Open(oRefDoc.FullDocumentName, False)
If oPDoc.PropertySets.Item("Design Tracking Properties").Item("Document SubType Name").Value = "Sheet Metal" Then
Dim oSMDef As SheetMetalComponentDefinition = oPDoc.ComponentDefinition
oName = IO.Path.GetFileNameWithoutExtension(oPDoc.FullFileName)
 
'here is your 'Custom' iProperties set
Dim oCProps As Inventor.PropertySet = oPDoc.PropertySets.Item("Inventor User Defined Properties")
 
'assemble your DXF file name here
Dim oCProp1 As String = oCProps.Item("#ITEM").Value
Dim oCProp2 As String = oCProps.Item("Thickness").Value
Dim oCProp3 As String = oCProps.Item("#CANT").Value
 
oDxfName = oFolder & oName & oCProp1 & "_" & oCProp2 & "_" & oCProp3 & "units" & ".dxf"
 
Dim oFPattern As FlatPattern
If oSMDef.HasFlatPattern = False Then
Try
'create flat pattern
oSMDef.Unfold
oFPattern = oSMDef.FlatPattern
Catch
'don't exit rule, just skip to the next loop document
MsgBox("Failed to 'Unfold' " & oPDoc.FullFileName & vbCrLf & _
"Skipping it and continuing to the next document.", , "")
Continue For
End Try
Else 'if flat pattern exists
oFPattern = oSMDef.FlatPattern
End If
 
Dim sOut As String = "FLAT PATTERN DXF?AcadVersion=2004" _
            + "&OuterProfileLayer=IV_INTERIOR_PROFILES" _
            + "&InvisibleLayers=IV_TANGENT;IV_FEATURE_PROFILES_DOWN;IV_BEND;IV_BEND_DOWN;IV_TOOL_CENTER;IV_TOOL_CENTER_DOWN;IV_ARC_CENTERS;IV_FEATURE_PROFILES;IV_FEATURE_PROFILES_DOWN;IV_ALTREP_FRONT;IV_ALTREP_BACK;IV_ROLL_TANGENT;IV_ROLL" _
            + "&SimplifySplines=True" _
            + "&BendLayerColor=255;255;0"
 
oFPattern.DataIO.WriteDataToFile(sOut, oFolder & "\" & oDxfName)
 
End If
oPDoc.Close(True)
End If
Next

 

Message 7 of 10
WCrihfield
in reply to: car_quezada

Hi @car_quezada.  I am not sure what may be the problem.  Does the code show an error message when you run it?  If so, can you tell us what it says (preferably in English).  Also, there are usually 2 tabs in the error message, and the tab named 'More Info' is better one to get the information from, because it contains more detailed information.  Also, if that error message says which line of code the error is being caused by, that would be very helpful for us to know also.

 

Looking back at my code from that earlier post, the first line of code beyond where the folder is created where I think might possibly cause a problem is this one:

If oPDoc.PropertySets.Item("Design Tracking Properties").Item("Document SubType Name").Value = "Sheet Metal" Then

...because it is checking for a name in English, when that value may be in another language.  Not sure if that is true or not though.  There are other lines of code that could be used there, for that same purpose though.  Try changing that line of code to this:

If TypeOf oPDoc.ComponentDefinition Is SheetMetalComponentDefinition Then

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 8 of 10
car_quezada
in reply to: shawn.budden

Hi @WCrihfield thanks for the quick response and interest. First, I need to apologize for the lack of formatting in my previous comment. I will try to make it better this time.

I tried changing the line in the code and something started to happen. Previously, I didn't receive any error messages; nothing happened. But now this error shows up. (I tried the code in a new assembly just in case, and on another computer.)

car_quezada_0-1715867795258.png

Just to reduse de error options, Im using Inventor 2023.4 (English)

 

So right know my code looks like this

 

'Sub Main()

'Check that the active document is an assembly file
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
	MessageBox.Show("Please run this rule from the assembly file.", "iLogic")
	Exit Sub
End If
Dim oADoc As AssemblyDocument
oADoc = ThisApplication.ActiveDocument

'Get user input
RUsure = MessageBox.Show ( _
"This will create a DXF file for all of the asembly components that are sheet metal." _
& vbLf & "This rule expects that the part file is saved." _
& vbLf & " " _
& vbLf & "Are you sure you want to create DXF for all of the assembly components?" _
& vbLf & "This could take a while.", "iLogic  - Batch Output DXFs ", MessageBoxButtons.YesNo)

If RUsure <> vbYes Then Exit Sub

'where to save all the DXF's to
Dim oFolder As String = "D:\Trabajo\TEST EXPORT DXF\"

'Check for the DXF folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then
    System.IO.Directory.CreateDirectory(oFolder)
End If

Dim oRefDoc As Document
Dim oPath, oName, oDxfName As String

For Each oRefDoc In oADoc.AllReferencedDocuments
	If oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
		Dim oPDoc As PartDocument = ThisApplication.Documents.Open(oRefDoc.FullDocumentName, False)
		If TypeOf oPDoc.ComponentDefinition Is SheetMetalComponentDefinition Then
			Dim oSMDef As SheetMetalComponentDefinition = oPDoc.ComponentDefinition
			oName = IO.Path.GetFileNameWithoutExtension(oPDoc.FullFileName)

			'here is your 'Custom' iProperties set
			Dim oCProps As Inventor.PropertySet = oPDoc.PropertySets.Item("Inventor User Defined Properties")
			
			'assemble your DXF file name here
			Dim oCProp1 As String = oCProps.Item("#ITEM").Value
			Dim oCProp2 As String = oCProps.Item("Thickness").Value
			Dim oCProp3 As String = oCProps.Item("#CANT").Value
			
			oDxfName = oFolder & oName & oCProp1 & "_" & oCProp2 & "_" & oCProp3 & "units" & ".dxf"
			
			Dim oFPattern As FlatPattern
			If oSMDef.HasFlatPattern = False Then
				Try
					'create flat pattern
					oSMDef.Unfold
					oFPattern = oSMDef.FlatPattern
				Catch
					'don't exit rule, just skip to the next loop document
					MsgBox("Failed to 'Unfold' " & oPDoc.FullFileName & vbCrLf & _
					"Skipping it and continuing to the next document.", , "")
					Continue For
				End Try
			Else 'if flat pattern exists
				oFPattern = oSMDef.FlatPattern
			End If
						
			Dim sOut As String = "FLAT PATTERN DXF?AcadVersion=2004" _
            + "&OuterProfileLayer=IV_INTERIOR_PROFILES" _
            + "&InvisibleLayers=IV_TANGENT;IV_FEATURE_PROFILES_DOWN;IV_BEND;IV_BEND_DOWN;IV_TOOL_CENTER;IV_TOOL_CENTER_DOWN;IV_ARC_CENTERS;IV_FEATURE_PROFILES;IV_FEATURE_PROFILES_DOWN;IV_ALTREP_FRONT;IV_ALTREP_BACK;IV_ROLL_TANGENT;IV_ROLL" _
            + "&SimplifySplines=True" _
            + "&BendLayerColor=255;255;0"
					
			oFPattern.DataIO.WriteDataToFile(sOut, oFolder & "\" & oDxfName)
	
		End If
		oPDoc.Close(True)
	End If
Next

 

 

 

Again thanks for the help

Message 9 of 10
WCrihfield
in reply to: car_quezada

OK.  I do see a couple things that are likely causing problems here.  The error message says it is throwing the error at the line of code that is calling the DataIO.WriteDataToFile method, but does not indicate any further reason for the error, so we must assume it has to do with what we are specifying as inputs into that method.  It is not an argument exception, so the inputs meet basic requirements, but are causing a different type of error.  I believe this is due to the full file name of the DXF file being specified there.  I say this, because I see earlier in your code where those two variables (oFolder & oDxfName) are being used, and see some problems there.  First of all, Line 22, where that 'oFolder' variable is first declared, and its initial value is set.  You are already including the "\" character at the end.  This by itself is not necessarily a problem.  However, in Line 71 you are adding another "\" character in there between the folder and file name, which would be too many to be valid.  But that is not all.  In Line 47, you are already including 'oFolder' within the value of the 'oDxfName' value (without the extra "\" character, which is correct).  So, the quickest way to fix this error might be to simply eliminate the "oFolder & "\" &" portion out of Line 71, leaving just the 'oDxfName' variable for that second input of that method.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 10 of 10
car_quezada
in reply to: WCrihfield

Thank you so much!! it finally work!! this is going to save me a ton of time now with large assemblies.
Again Im pretty new with Ilogic so this will take me much more time to realize by my self.
I see you have a lot of experience with Ilogic and probably VB, can you give me an advise to introduce my self in a better and more efficent way to this area? Im really interested in it.

Thanks again!!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report