Batch export flat pattern dxf from iAssembly Factory

Batch export flat pattern dxf from iAssembly Factory

KrishR330
Contributor Contributor
492 Views
0 Replies
Message 1 of 1

Batch export flat pattern dxf from iAssembly Factory

KrishR330
Contributor
Contributor

Hi Everyone/Anyone,

 

I am currently using below modified iLogic Code from another forum. It only works for a simple assembly and not for an entire iAssembly Factory. Please share your ideas and help me complete my code.

 

Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
oAsmName = ThisDoc.FileName(False) 'without extension

'Check that the active document is an assembly file
If oDoc.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 assembly 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

Dim oPath As String = ThisDoc.Path

'Get the DXF target folder path
Dim oFolder As String = oPath & "\" & " DXF Files"

'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

'- - - - - - - - - - - - -Component  - - - - - - - - - - - -
'MessageBox.Show("Test", "My iLogic Dialog", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1)
Dim oBOM As BOM
'MessageBox.Show("Test", "My iLogic Dialog", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1)
oBOM = oDoc.ComponentDefinition.BOM
'MessageBox.Show("Test", "My iLogic Dialog", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1)

oBOM.StructuredViewEnabled = True
Dim oBOMView As BOMView = oBOM.BOMViews.Item(oBOM.BOMViews.Count)
For Each oRow As BOMRow In oBOMView.BOMRows
Try
	Dim oCD As ComponentDefinition = oRow.ComponentDefinitions.Item(1)
	Dim iDoc As Document = oCD.Document
	'SheetMetal parts only
	If iDoc.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then Continue For
	Dim iName As String = iDoc.FullFileName

	'Check that model is saved
	If iName = vbNullString Then Continue For
	iDoc = ThisApplication.Documents.Open(iName)
	oCD = iDoc.ComponentDefinition
	
	Dim oItem As String = oRow.ItemNumber
	Try
		If Not oCD.HasFlatPattern Then
			oCD.Unfold()
		Else
			oCD.FlatPattern.Edit()
		End If

		Dim sOut As String = "FLAT PATTERN DXF?AcadVersion=2004&OuterProfileLayer=IV_OUTER_PROFILE&InvisibleLayers=IV_TANGENT&BendDownLayerLineType=37644&BendUpLayerLineType=37644"
				
		Dim ShortName As String = Left(iDoc.DisplayName, (InStrRev(iDoc.DisplayName, ".", -1, vbTextCompare) - 1)) & ".dxf"

		oCD.DataIO.WriteDataToFile(sOut, oFolder & "\" & ShortName)
		oCD.FlatPattern.ExitEdit()
	Catch ex As Exception
		MsgBox(ex.Message)
	End Try
	iDoc.Close(True)
Catch
End Try
Next

 

0 Likes
493 Views
0 Replies
Replies (0)