I want to write quantity information at the end of the DXF file.

I want to write quantity information at the end of the DXF file.

ersin_karacoban
Participant Participant
460 Views
3 Replies
Message 1 of 4

I want to write quantity information at the end of the DXF file.

ersin_karacoban
Participant
Participant

With the iLogic code below, I export my components in the assembly as DXF. But I want to print the quantity information at the end of the exported files. It can get the number of pieces from the BOM. For example;

2301 05 02 - 16 QTY

 

Sub Main()
    
    Dim New_Folder_Path As String = ThisDoc.Path
    Dim oAsmDoc As AssemblyDocument = ThisDoc.Document
 
    My.Computer.FileSystem.CreateDirectory(New_Folder_Path)
    
    'Ask user for REV level
    Dim Rev_Level As String = ""
    Rev_Level = InputBox ("Enter Rev Level","Creating DXF files For Entire Assembly")
    
    Dim Count_up As Integer = 0
    Dim Gauge_Folders(12) As String
    Dim Ga As String
    Dim doc As Document
	Dim R_Part As String
	Dim oMaterial As Material
    
    For Each doc In oAsmDoc.AllReferencedDocuments 
        If doc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then 
			Try
				R_Part = doc.DisplayName
				oMaterial = doc.ComponentDefinition.Material
				Gauge_Path = New_Folder_Path & "\" & Parameter(R_Part, "Thickness") & " " & oMaterial.Name
							MessageBox.Show(Gauge_Path )
				Try
					My.Computer.FileSystem.CreateDirectory(Gauge_Path)						
				Catch
				End Try
            	Call Make_DXF(doc, Rev_Level, Gauge_Path)		
			Catch
			End Try		
		End If
    Next 
MsgBox("DXF Export Complete",,"All Done")		
    
End Sub
    
Sub Make_DXF(oDoc As Document, Rev_L As String, File_Location As String)

	ThisApplication.Documents.Open(oDoc.FullFileName, True)
		
	Dim Part_Name As String = oDoc.DisplayName
	Dim TestPos As Integer = 0

	Dim Rev_Adder As String = ""
	If Rev_L <> "" Then Rev_Adder = " REV " & Rev_L

	TestPos = InStr(1, Part_Name, ".")

	If TestPos <> 0 Then Part_Name = Left(Part_Name, InStr(Part_Name, ".")-1)

	Dim New_Name As String = Part_Name 

	Dim oFilename As String  = File_Location & "\" & New_Name & Rev_Adder & ".dxf"

	Dim oCompDef As SheetMetalComponentDefinition = oDoc.ComponentDefinition

	If oCompDef.HasFlatPattern = False Then 
		oCompDef.Unfold
	Else
		oCompDef.FlatPattern.Edit
	End If

	Dim oFlatPattern As FlatPattern = oCompDef.FlatPattern
	Dim oFace As Face = oFlatPattern.TopFace

	Dim oCommand As CommandManager = ThisApplication.CommandManager

	oCommand.DoSelect(oFace)
	oCommand.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent,oFilename) 
	oCommand.ControlDefinitions.Item("GeomToDXFCommand").Execute2(True)

	oCompDef.FlatPattern.ExitEdit
	oDoc.Close

End Sub

 

 

0 Likes
Accepted solutions (2)
461 Views
3 Replies
Replies (3)
Message 2 of 4

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

Hi @ersin_karacoban . Please try this code:

Sub Main()
    
    Dim New_Folder_Path As String = ThisDoc.Path
    Dim oAsmDoc As AssemblyDocument = ThisDoc.Document
 
    My.Computer.FileSystem.CreateDirectory(New_Folder_Path)
    
    'Ask user for REV level
    Dim Rev_Level As String = ""
    Rev_Level = InputBox ("Enter Rev Level","Creating DXF files For Entire Assembly")
    
    Dim Count_up As Integer = 0
    Dim Gauge_Folders(12) As String
    Dim Ga As String
    Dim doc As Document
	Dim R_Part As String
	Dim oMaterial As Material
	
	Dim oOccs As ComponentOccurrences = oAsmDoc.ComponentDefinition.Occurrences
    
    For Each doc In oAsmDoc.AllReferencedDocuments
		Dim iQty As Integer = oOccs.AllReferencedOccurrences(doc).Count
        If doc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then 
			Try
				R_Part = doc.DisplayName
				oMaterial = doc.ComponentDefinition.Material
				Gauge_Path = New_Folder_Path & "\" & Parameter(R_Part, "Thickness") & " " & oMaterial.Name
							MessageBox.Show(Gauge_Path )
				Try
					My.Computer.FileSystem.CreateDirectory(Gauge_Path)						
				Catch
				End Try
            	Call Make_DXF(doc, Rev_Level, Gauge_Path, iQty)		
			Catch
			End Try		
		End If
    Next 
MsgBox("DXF Export Complete",,"All Done")		
    
End Sub
    
Sub Make_DXF(oDoc As Document, Rev_L As String, File_Location As String, ByVal iQty As Integer)

	ThisApplication.Documents.Open(oDoc.FullFileName, True)
		
	Dim Part_Name As String = oDoc.DisplayName
	Dim TestPos As Integer = 0

	Dim Rev_Adder As String = ""
	If Rev_L <> "" Then Rev_Adder = " REV " & Rev_L

	TestPos = InStr(1, Part_Name, ".")

	If TestPos <> 0 Then Part_Name = Left(Part_Name, InStr(Part_Name, ".")-1)

	Dim New_Name As String = Part_Name 

	Dim oFilename As String  = File_Location & "\" & New_Name & Rev_Adder & " - " & iQty & " QTY.dxf"

	Dim oCompDef As SheetMetalComponentDefinition = oDoc.ComponentDefinition

	If oCompDef.HasFlatPattern = False Then 
		oCompDef.Unfold
	Else
		oCompDef.FlatPattern.Edit
	End If

	Dim oFlatPattern As FlatPattern = oCompDef.FlatPattern
	Dim oFace As Face = oFlatPattern.TopFace

	Dim oCommand As CommandManager = ThisApplication.CommandManager

	oCommand.DoSelect(oFace)
	oCommand.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent,oFilename) 
	oCommand.ControlDefinitions.Item("GeomToDXFCommand").Execute2(True)

	oCompDef.FlatPattern.ExitEdit
	oDoc.Close

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 4

ersin_karacoban
Participant
Participant

Hi @Andrii_Humeniuk . Thanks for your help. It's working. How can I print the number of pieces multiplied by, for example, 4?

0 Likes
Message 4 of 4

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

You need to change line 33 - iQty*4

Call Make_DXF(doc, Rev_Level, Gauge_Path, iQty*4)	

 

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