Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
filippo.costantin3HZMT
311 Views, 3 Replies

Export DXF Flat pattern in sub-assembly with iLogic

Hi everyone, 

 

I'm trying to export the dxf flat pattern of sheet metal part in assembly B that is place in Assembly A. 

I tryed to use this rule, but it didn't run correcty.  Where is the error?

'IPT_OM_template is the name of Assembly in the rule
Sub Print_Assembly_IPT_DXF(IPT_OM_Template As String, pathOutputDXF As String)
	   
	Dim oAsm As AssemblyDocument
	Dim oPenDoc as Document=ThisDoc.Document
	Dim AsmCompDefMainL0 As AssemblyComponentDefinition = ThisApplication.ActiveDocument.ComponentDefinition
	Dim AsmCompDefL1 As AssemblyComponentDefinition = ThisApplication.ActiveDocument.ComponentDefinition
	Dim OccurMainL0 As ComponentOccurrence
	Dim OccurL1 as ComponentOccurrence
	Dim AsmCompMainL0 As ComponentDefinition = ThisDoc.Document.ComponentDefinition
	Dim AsmCompMainL1 As ComponentDefinition = ThisDoc.Document.ComponentDefinition

	For Each OccurMainL0  In AsmCompDefMainL0.Occurrences
	Dim oOccNameL0 As String = OccurMainL0.Name
	Dim thisAssembly as AssemblyDocument = oOccNameL0
	Logger.Info("Apro assieme per DXF: " & oOccNameL0)
		'If OccurMainL0.Definition.Type = ObjectTypeEnum.kAssemblyComponentDefinitionObject Then
			'For Each OccurL1 In OccurMainL0.SubOccurrences
			For Each doc In thisAssembly.AllReferencedDocuments
			Dim parsedPartName = doc.DisplayName
			Logger.Info("Selezionare parte da esportare in DXF: " & parsedPartName)
			if parsedPartName.Contains("CTG") Then
			Logger.Info("Ho selezionato la parte in CTG")
			Else
			Logger.Info("Ho selezionato la parte in lamiera")
			Dim sOut      As String = "FLAT PATTERN DXF?AcadVersion=2004&OuterProfileLayer=OUTER_PR​OFILE&OuterProfileLayerColor=0;0;0&InteriorProfilesLayer=INNER_PROFILE&InteriorProfilesLayerColor=0;0;0&InvisibleLayers=IV_BEND;IV_BEND_DOWN;IV_UNCONSUMED_SKETCH;IV_ARC_CENTERS;IV_TANGENT;IV_ROLL;IV_ROLL_TANGENT;IV_ALTREP_BACK;IV_ALTREP_FRONT;IV_FEATURE_PROFILES_DOWN;IV_FEATURE_PROFILES;IV_TOOL_CENTER;IV_TOOL_CENTER_DOWN;DIGI_MARKER_TOOL_1;DIGI_MARKER_TOOL_2"
			Dim component As SheetMetalComponentDefinition = doc.ComponentDefinition
			Dim PathDXF as String = pathOutputLamieraDXF & iProperties.Value(OccurL1, "Custom", "Nome_File")
			component.Unfold
		
			If System.IO.File.Exists(pathOutputDXF) = True Then
				System.IO.File.Delete(pathOutputDXF)
			End If
			component.DataIO.WriteDataToFile(sOut, PathDXF )
			Logger.Info("DXF " & SharedVariable("VPR_Codice") & " SUCCESS")
			component.FlatPattern.ExitEdit()
			doc.Close()
			End if
			Next
		'End if
	Next
End Sub

Hello

 

Which row of your Code is right? It seems you mixed two scripts together.

Is your script called by another script or should it run alone? I assume you calling this script by a Main sub. You will have to fill the string variables for template name and output path. There is a shared variable "VPR_Codice" and I assume it is set elsewhere. There is a variable "pathOutputLamieraDXF" used, but not set anywhere.

I've commented unused code.

 

Perhaps it will help, otherwise you have to post more details. It didn't run correctly is a little bit less information. :winking_face:

 

Sub Main()
	Dim IPT_OM_Template As String = ""	'<--- Fill missing Text
	Dim pathOutputDXF As String = ""		'<--- Fill missing Text
	
	Call Print_Assembly_IPT_DXF(IPT_OM_Template, pathOutputDXF)
End Sub	

'IPT_OM_template is the name of Assembly in the rule
Sub Print_Assembly_IPT_DXF(IPT_OM_Template As String, pathOutputDXF As String)
	   
	Dim oAsm As AssemblyDocument = ThisDoc.Document 
	'Dim oPenDoc As Document=ThisDoc.Document
	Dim AsmCompDefMainL0 As AssemblyComponentDefinition = oAsm.ComponentDefinition 'ThisApplication.ActiveDocument.ComponentDefinition
	Dim AsmCompDefL1 As AssemblyComponentDefinition '= ThisApplication.ActiveDocument.ComponentDefinition
	Dim OccurMainL0 As ComponentOccurrence
	Dim OccurL1 As ComponentOccurrence
	'Dim AsmCompMainL0 As ComponentDefinition = ThisDoc.Document.ComponentDefinition
	'Dim AsmCompMainL1 As ComponentDefinition = ThisDoc.Document.ComponentDefinition

	For Each OccurMainL0  In AsmCompDefMainL0.Occurrences
		Dim oOccNameL0 As String = OccurMainL0.Name
		Dim thisAssembly As AssemblyDocument = oOccNameL0
		Logger.Info("Apro assieme per DXF: " & oOccNameL0)
		If OccurMainL0.Definition.Type = ObjectTypeEnum.kAssemblyComponentDefinitionObject Then
			For Each OccurL1 In OccurMainL0.SubOccurrences
			'For Each doc In thisAssembly.AllReferencedDocuments
				If OccurL1.Definition.Type=ObjectTypeEnum.kSheetMetalComponentDefinitionObject Then
					Dim parsedPartName = OccurL1.ReferencedDocumentDescriptor.DisplayName ' doc.DisplayName
					Logger.Info("Selezionare parte da esportare in DXF: " & parsedPartName)
					If parsedPartName.Contains("CTG") Then
						Logger.Info("Ho selezionato la parte in CTG")
					Else
						Logger.Info("Ho selezionato la parte in lamiera")
						Dim sOut      As String = "FLAT PATTERN DXF?AcadVersion=2004&OuterProfileLayer=OUTER_PR​OFILE&OuterProfileLayerColor=0;0;0&InteriorProfilesLayer=INNER_PROFILE&InteriorProfilesLayerColor=0;0;0&InvisibleLayers=IV_BEND;IV_BEND_DOWN;IV_UNCONSUMED_SKETCH;IV_ARC_CENTERS;IV_TANGENT;IV_ROLL;IV_ROLL_TANGENT;IV_ALTREP_BACK;IV_ALTREP_FRONT;IV_FEATURE_PROFILES_DOWN;IV_FEATURE_PROFILES;IV_TOOL_CENTER;IV_TOOL_CENTER_DOWN;DIGI_MARKER_TOOL_1;DIGI_MARKER_TOOL_2"
						Dim component As SheetMetalComponentDefinition = OccurL1.Definition
						'Dim PathDXF As String = pathOutputLamieraDXF & iProperties.Value(OccurL1, "Custom", "Nome_File")
						component.Unfold
			
						If System.IO.File.Exists(pathOutputDXF) = True Then
							System.IO.File.Delete(pathOutputDXF)
						End If
						'component.DataIO.WriteDataToFile(sOut, pathDXF)
						component.DataIO.WriteDataToFile(sOut, pathOutputDXF )
						Logger.Info("DXF " & SharedVariable("VPR_Codice") & " SUCCESS")
						component.FlatPattern.ExitEdit()
						'component.Document.close()
					End If
				End If
			Next
		End If
	Next
End Sub

 


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

Hi, 

 

thanks for your answer. Yes I use a Sub Main () for this code. 

here the input that you need:

IPT_OM Template is the name of the assembly

Path_Output_DXF is the path of folder where I would save the DXF flat pattern of part. 

SharedVariable("pathOutputLamieraDXF")     = SharedVariable("thisDocPath") & "\Output_DXF\" 
 
I attached the assembly which I use for create the assembly. 

 

 IPT_OM_Template

 

Hello

 

First, you posted only the iam, the included 3 ipt's are missing.

Anyway, I'll tried to modify the code so you could try to paste it in your assembly.

 

Sub Main()
	SharedVariable("VPR_Codice") = ""
	
	Dim IPT_OM_Template As String = ThisDoc.FileName(False) 'Filename of the assembly without file type extension (iam)
	Dim pathOutputDXF As String = ThisDoc.Path & "\Output_DXF\"  & IPT_OM_Template & ".dxf" 'Path to save the dxf to including filename of assembly and file type extension (dxf)
	
	Call Print_Assembly_IPT_DXF(IPT_OM_Template, pathOutputDXF)
End Sub	

Sub Print_Assembly_IPT_DXF(IPT_OM_Template As String, pathOutputDXF As String)
	   
	Dim oAsm As AssemblyDocument = ThisDoc.Document 
	'Dim oPenDoc As Document=ThisDoc.Document
	Dim AsmCompDefMainL0 As AssemblyComponentDefinition = oAsm.ComponentDefinition 'ThisApplication.ActiveDocument.ComponentDefinition
	Dim AsmCompDefL1 As AssemblyComponentDefinition '= ThisApplication.ActiveDocument.ComponentDefinition
	Dim OccurMainL0 As ComponentOccurrence
	Dim OccurL1 As ComponentOccurrence
	'Dim AsmCompMainL0 As ComponentDefinition = ThisDoc.Document.ComponentDefinition
	'Dim AsmCompMainL1 As ComponentDefinition = ThisDoc.Document.ComponentDefinition

	For Each OccurMainL0  In AsmCompDefMainL0.Occurrences
		Dim oOccNameL0 As String = OccurMainL0.Name
		'Dim thisAssembly As AssemblyDocument = OccurMainL0.Definition.Document 
		Logger.Info("Apro assieme per DXF: " & oOccNameL0)
		If OccurMainL0.Definition.Type = ObjectTypeEnum.kAssemblyComponentDefinitionObject Then
			For Each OccurL1 In OccurMainL0.SubOccurrences
			'For Each doc In thisAssembly.AllReferencedDocuments
				If OccurL1.Definition.Type = ObjectTypeEnum.kSheetMetalComponentDefinitionObject Then
					Dim parsedPartName = OccurL1.ReferencedDocumentDescriptor.DisplayName ' doc.DisplayName
					Logger.Info("Selezionare parte da esportare in DXF: " & parsedPartName)
					If parsedPartName.Contains("CTG") Then
						Logger.Info("Ho selezionato la parte in CTG")
					Else
						Logger.Info("Ho selezionato la parte in lamiera")
						Dim sOut As String = "FLAT PATTERN DXF?AcadVersion=2004&OuterProfileLayer=OUTER_PR​OFILE&OuterProfileLayerColor=0;0;0&InteriorProfilesLayer=INNER_PROFILE&InteriorProfilesLayerColor=0;0;0&InvisibleLayers=IV_BEND;IV_BEND_DOWN;IV_UNCONSUMED_SKETCH;IV_ARC_CENTERS;IV_TANGENT;IV_ROLL;IV_ROLL_TANGENT;IV_ALTREP_BACK;IV_ALTREP_FRONT;IV_FEATURE_PROFILES_DOWN;IV_FEATURE_PROFILES;IV_TOOL_CENTER;IV_TOOL_CENTER_DOWN;DIGI_MARKER_TOOL_1;DIGI_MARKER_TOOL_2"
						Dim component As SheetMetalComponentDefinition = OccurL1.Definition
						'Dim PathDXF As String = pathOutputLamieraDXF & iProperties.Value(OccurL1, "Custom", "Nome_File")

						component.Unfold

						If System.IO.File.Exists(pathOutputDXF) = True Then
							System.IO.File.Delete(pathOutputDXF)
						End If
						component.DataIO.WriteDataToFile(sOut, pathOutputDXF)
						Logger.Info("DXF " & SharedVariable("VPR_Codice") & " SUCCESS")
						component.FlatPattern.ExitEdit()
						'component.Document.close()
					End If
				End If
			Next
		End If
	Next
End Sub

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