Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
firelinsgs
in reply to: Anonymous

Hi,

 

Try this one. We can also add counting the parts per assembly and write the Quantity to name file.

 

 

Sub Main
	Dim oDoc As Document = ThisApplication.ActiveDocument
	If oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
		If oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then Export(oDoc)
		Exit Sub
	End If
	Cycle(oDoc)
End Sub

Sub Cycle(oDoc As AssemblyDocument)
	For Each aDoc As Document In oDoc.ReferencedDocuments
		If aDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
			Export(aDoc)
		ElseIf aDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
			Cycle(aDoc)
		End If
	Next
End Sub

Sub Export(oDoc As PartDocument)
	Dim FName As String = GetFName(oDoc.FullFileName)
	Dim sPN As String = iProperties.Value(FName, "Project", "Part Number")
	Dim Rev As String = iProperties.Value(FName, "Project", "Revision Number")
	Dim oCD As SheetMetalComponentDefinition = oDoc.ComponentDefinition
	If Not oCD.HasFlatPattern Then
		oCD.Unfold()
		oCD.FlatPattern.ExitEdit()
	End If
	
	If Rev = Nothing Then Rev = "00"
		
	Dim dThick As Double
	Try
		dThick = Math.Round(oCD.Parameters("Tloušťka").Value * 10, 1)
	Catch
		Exit Sub
	End Try
	If dThick < 0.05 Then Exit Sub
	Dim sOut As String = "FLAT PATTERN DXF?AcadVersion=2013&InvisibleLayers=IV_TANGENT;IV_BEND;IV_BEND_DOWN;IV_ARC_CENTERS"
	FName = oDoc.FullFileName
	Dim FNP As Integer = InStrRev(FName, "\", -1)
	Dim sPath As String = Left(FName, FNP)
	FNP = InStr(sPath, "\")
	sPath = "C:\DXF" & Mid(sPath, FNP)
	If Not System.IO.Directory.Exists(sPath) Then System.IO.Directory.CreateDirectory(sPath)
	Dim sNewName As String = sPath & sPN & "_" & Rev & "_" & CStr(dThick) & "mm" & ".dxf"
	oCD.DataIO.WriteDataToFile(sOut, sNewName)
End Sub

Function GetFName(FullName As String) As String
	Dim FNP As Integer = InStrRev(FullName, "\", - 1)
	Dim FName As String = Mid(FullName, FNP + 1, Len(FullName) - FNP)
	Return FName
End Function