Name and number in the name of the exported dxf file

Name and number in the name of the exported dxf file

J.J.Kucharczyk
Contributor Contributor
601 Views
6 Replies
Message 1 of 7

Name and number in the name of the exported dxf file

J.J.Kucharczyk
Contributor
Contributor

Thank you in advance for your understanding. I am completely new to iLogic.

For the last 2 weeks I have been trying to obtain the code that exports the design to dxf files for laser cutting.
I have modified several codes and have come up with one that works almost perfect.

I would like the DXF file name to be in the format:

(Thickness) - (Quantity) - (File name) - (material type).dxf

At the moment there is only the name and the extension.

Below is the code I am using.

What should I change?

Thank you for any advice.

 

 

Dim oDoc As Document
oDoc=ThisDoc.Document
Dim docFile As Document
For Each docFile In oDoc.AllReferencedDocuments
ThisApplication.Documents.Open(docFile.FullFileName,True)
Dim partDoc As PartDocument
partDoc=ThisApplication.ActiveDocument
If partDoc.SubType="{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
Dim oCompDef As SheetMetalComponentDefinition
oCompDef=partDoc.ComponentDefinition
Dim oDataIO As DataIO
oDataIO=oDoc.ComponentDefinition.DataIO
If oCompDef.HasFlatPattern=False Then
oCompDef.Unfold
Else
oCompDef.FlatPattern.Edit
End If

Dim sOut As String = "FLAT PATTERN DWG?AcadVersion=2000" _
+"&InvisibleLayers=IV_TANGENT;IV_BEND;IV_BEND_DOWN;IV_TOOL_CENTER;IV_TOOL_CENTER_DOWN;IV_ARC_CENTERS;IV_FEATURE_PROFILES;IV_UNCONSUMED_SKETCHES;IV_ROLL_TANGENT;IV_ROLL;IV_FEATURE_PROFILES_DOWN" _
+"&SimplifySplines=True" _
+"&LINEAR TOLERANCE=0.010" _
+"&MergeProfilesIntoPolyline=True" _
+"&RebaseGeometry=False" _
+"&TrimCenterlines=True"

Dim invPropSets As PropertySets
invPropSets=partDoc.PropertySets
Dim invPropSet As PropertySet
invPropSet=invPropSets.Item("Design Tracking Properties")
Dim invPartNumiProp As Inventor.Property
invPartNumiProp = invPropSet.Item("Part Number")

Dim invPartQty As Inventor.Property
invPropSet2 = invPartQty

Dim sFname As String
sFname=ThisDoc.Path &"\"& invPartNumiProp.Value & SheetMetal.GetActiveStyle &".dxf"
oCompDef.DataIO.WriteDataToFile(sOut,sFname)
oCompDef.FlatPattern.ExitEdit
If partDoc.ComponentDefinition.IsiPartFactory Or
partDoc.ComponentDefinition.IsiPartMember Then
partDoc.Save()
End If
Else
End If
partDoc.Close
Next

 

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

Andrii_Humeniuk
Advisor
Advisor

Hi @J.J.Kucharczyk . I rewrote the logic of your rule. Please try to see if the rule works normally.

Private Sub Main()
	Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
	Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
	Dim oBOMView As BOMView = GetBOMpartsOnly(oDef.BOM)
	For Each oRow As BOMRow In oBOMView.BOMRows
		Dim oRowDef As ComponentDefinition = oRow.ComponentDefinitions.Item(1)
		Dim partDoc As PartDocument = oRowDef.Document
		If partDoc.SubType="{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
			Dim oCompDef As SheetMetalComponentDefinition = oRow.ComponentDefinitions.Item(1)
			Dim oDataIO As DataIO = oDoc.ComponentDefinition.DataIO
			If oCompDef.HasFlatPattern=False Then
				oCompDef.Unfold
			Else
				oCompDef.FlatPattern.Edit
			End If
			
			Dim sOut As String = "FLAT PATTERN DWG?AcadVersion=2000" _
			+"&InvisibleLayers=IV_TANGENT;IV_BEND;IV_BEND_DOWN;IV_TOOL_CENTER;IV_TOOL_CENTER_DOWN;IV_ARC_CENTERS;IV_FEATURE_PROFILES;IV_UNCONSUMED_SKETCHES;IV_ROLL_TANGENT;IV_ROLL;IV_FEATURE_PROFILES_DOWN" _
			+"&SimplifySplines=True" _
			+"&LINEAR TOLERANCE=0.010" _
			+"&MergeProfilesIntoPolyline=True" _
			+"&RebaseGeometry=False" _
			+"&TrimCenterlines=True"
			
			Dim invPropSets As PropertySets = partDoc.PropertySets
			Dim invPropSet As PropertySet = invPropSets.Item("Design Tracking Properties")
			Dim invPartNumiProp As Inventor.Property = invPropSet.Item("Part Number")
			
			Dim dThick As Double = oCompDef.Thickness.Value
			Dim iQ As Integer = oRow.TotalQuantity
			Dim sName As String = partDoc.DisplayName
			Dim sMaterial As String = partDoc.ActiveMaterial.DisplayName
			Dim sFname As String = ThisDoc.Path & "\" & dThick & " - " & iQ & " - " & sName & " - " & sMaterial &".dxf"
'			Dim sFname As String = ThisDoc.Path & "\" & invPartNumiProp.Value & SheetMetal.GetActiveStyle &".dxf"
			oCompDef.DataIO.WriteDataToFile(sOut,sFname)
			oCompDef.FlatPattern.ExitEdit
			If partDoc.ComponentDefinition.IsiPartFactory Or
				partDoc.ComponentDefinition.IsiPartMember Then
				partDoc.Save()
			End If
		End If
	Next	
End Sub

Private Function GetBOMpartsOnly(ByVal oBOM As BOM) As BOMView
	Dim oLanguageBOM As String
	Select Case ThisApplication.LanguageCode
	Case "en-US"
		oLanguageBOM = "Parts Only"
		Exit Function
	End Select	
	If oBOM.PartsOnlyViewEnabled = False Then
		oBOM.PartsOnlyViewEnabled = True
	End If
	Return oBOM.BOMViews.Item(oLanguageBOM)
End Function

  

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

0 Likes
Message 3 of 7

J.J.Kucharczyk
Contributor
Contributor

Thanks for the quick response.
A message like this is occurring.

 

Skærmbillede 2023-06-01 132651.jpg

0 Likes
Message 4 of 7

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

I made a mistake on line 50. It should work fine now. Note that the thickness is written in cm, if you need other units then change line 29.

Private Sub Main()
	Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
	Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
	Dim oBOMView As BOMView = GetBOMpartsOnly(oDef.BOM)
	For Each oRow As BOMRow In oBOMView.BOMRows
		Dim oRowDef As ComponentDefinition = oRow.ComponentDefinitions.Item(1)
		Dim partDoc As PartDocument = oRowDef.Document		
		If partDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
			Dim oCompDef As SheetMetalComponentDefinition = oRow.ComponentDefinitions.Item(1)
			Dim oDataIO As DataIO = oDoc.ComponentDefinition.DataIO
			If oCompDef.HasFlatPattern=False Then
				oCompDef.Unfold
			Else
				oCompDef.FlatPattern.Edit
			End If
			
			Dim sOut As String = "FLAT PATTERN DWG?AcadVersion=2000" _
			+"&InvisibleLayers=IV_TANGENT;IV_BEND;IV_BEND_DOWN;IV_TOOL_CENTER;IV_TOOL_CENTER_DOWN;IV_ARC_CENTERS;IV_FEATURE_PROFILES;IV_UNCONSUMED_SKETCHES;IV_ROLL_TANGENT;IV_ROLL;IV_FEATURE_PROFILES_DOWN" _
			+"&SimplifySplines=True" _
			+"&LINEAR TOLERANCE=0.010" _
			+"&MergeProfilesIntoPolyline=True" _
			+"&RebaseGeometry=False" _
			+"&TrimCenterlines=True"
			
			Dim invPropSets As PropertySets = partDoc.PropertySets
			Dim invPropSet As PropertySet = invPropSets.Item("Design Tracking Properties")
			Dim invPartNumiProp As Inventor.Property = invPropSet.Item("Part Number")
			
			Dim dThick As Double = oCompDef.Thickness.Value
			Dim iQ As Integer = oRow.TotalQuantity
			Dim sName As String = partDoc.DisplayName
			Dim sMaterial As String = partDoc.ActiveMaterial.DisplayName
			Dim sFname As String = ThisDoc.Path & "\" & dThick & " - " & iQ & " - " & sName & " - " & sMaterial &".dxf"
'			Dim sFname As String = ThisDoc.Path & "\" & invPartNumiProp.Value & SheetMetal.GetActiveStyle &".dxf"
			oCompDef.DataIO.WriteDataToFile(sOut,sFname)
			oCompDef.FlatPattern.ExitEdit
			If partDoc.ComponentDefinition.IsiPartFactory Or
				partDoc.ComponentDefinition.IsiPartMember Then
				partDoc.Save()
			End If
		End If
	Next	
End Sub

Private Function GetBOMpartsOnly(ByVal oBOM As BOM) As BOMView
	Dim oLanguageBOM As String
	Select Case ThisApplication.LanguageCode
	Case "en-US"
		oLanguageBOM = "Parts Only"
	Case Else
		Exit Function
	End Select	
	If oBOM.PartsOnlyViewEnabled = False Then
		oBOM.PartsOnlyViewEnabled = True
	End If
	Return oBOM.BOMViews.Item(oLanguageBOM)
End Function

 

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

0 Likes
Message 5 of 7

J.J.Kucharczyk
Contributor
Contributor

Thank you Andrii. 

 

Now have : 

Error on line 14 in rule: NY Assebly to dxf, in document: Test DXF ny.iam

Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))

 

Under more info: 

System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.FlatPattern.Edit()
at ThisRule.Main() in external rule: NY Assebly to dxf:line 14
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

0 Likes
Message 6 of 7

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

This code works perfectly for me, you start having problems when editing the FlatPatternI added the opening of the document, maybe it will help you. Please check the following code:

Private Sub Main()
	Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
	Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
	Dim oBOMView As BOMView = GetBOMpartsOnly(oDef.BOM)
	For Each oRow As BOMRow In oBOMView.BOMRows
		Dim oRowDef As ComponentDefinition = oRow.ComponentDefinitions.Item(1)
		Dim partDoc As PartDocument = oRowDef.Document
		If partDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
			Dim oCompDef As SheetMetalComponentDefinition = oRow.ComponentDefinitions.Item(1)
			Dim openDoc As Document = ThisApplication.Documents.Open(partDoc.FullDocumentName, True)
			
			If Not oCompDef.HasFlatPattern Then
				oCompDef.Unfold()
			Else
				oCompDef.FlatPattern.Edit()
			End If
			
			Dim sOut As String = "FLAT PATTERN DWG?AcadVersion=2000" _
			+"&InvisibleLayers=IV_TANGENT;IV_BEND;IV_BEND_DOWN;IV_TOOL_CENTER;IV_TOOL_CENTER_DOWN;IV_ARC_CENTERS;IV_FEATURE_PROFILES;IV_UNCONSUMED_SKETCHES;IV_ROLL_TANGENT;IV_ROLL;IV_FEATURE_PROFILES_DOWN" _
			+"&SimplifySplines=True" _
			+"&LINEAR TOLERANCE=0.010" _
			+"&MergeProfilesIntoPolyline=True" _
			+"&RebaseGeometry=False" _
			+"&TrimCenterlines=True"
			
			Dim invPropSets As PropertySets = partDoc.PropertySets
			Dim invPropSet As PropertySet = invPropSets.Item("Design Tracking Properties")
			Dim invPartNumiProp As Inventor.Property = invPropSet.Item("Part Number")
			
			Dim sPath As String = System.IO.Path.GetDirectoryName(partDoc.FullFileName)
			Dim dThick As Double = oCompDef.Thickness.Value
			Dim iQ As Integer = oRow.TotalQuantity
			Dim sName As String = partDoc.DisplayName
			Dim sMaterial As String = partDoc.ActiveMaterial.DisplayName
			Dim sFname As String = sPath & "\" & dThick & " - " & iQ & " - " & sName & " - " & sMaterial &".dxf"
			oCompDef.DataIO.WriteDataToFile(sOut,sFname)
			oCompDef.FlatPattern.ExitEdit()
			If partDoc.ComponentDefinition.IsiPartFactory Or partDoc.ComponentDefinition.IsiPartMember Then
				partDoc.Save()
			End If
			openDoc.Close()
		End If
	Next	
End Sub

Private Function GetBOMpartsOnly(ByVal oBOM As BOM) As BOMView
	Dim oLanguageBOM As String
	Select Case ThisApplication.LanguageCode
	Case "en-US"
		oLanguageBOM = "Parts Only"
	Case "ru-RU"
		oLanguageBOM = "Только детали"
	Case Else
		Exit Function
	End Select	
	If oBOM.PartsOnlyViewEnabled = False Then
		oBOM.PartsOnlyViewEnabled = True
	End If
	Return oBOM.BOMViews.Item(oLanguageBOM)
End Function

 

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

0 Likes
Message 7 of 7

J.J.Kucharczyk
Contributor
Contributor

I'm sorry that I'm answering week later, but I was on hollidays 🙂 

 

Thanks a lot! I will check all of your codes ASAP. 

 

Once again thnak you! 

 

 

EDIT:
Code from message 4 works fine 🙂 THANK YOU!!!!!!! 
Thickness displayed for example for 4mm was 0.4 , so I just  added the multiplier (*10).  

All the best!