Multiply dxf with filename quantity - from sub assembly

Multiply dxf with filename quantity - from sub assembly

guido_maniglia
Enthusiast Enthusiast
501 Views
7 Replies
Message 1 of 8

Multiply dxf with filename quantity - from sub assembly

guido_maniglia
Enthusiast
Enthusiast

Hi all,

I'm using this code to extract DXFs from an Inventor assembly.
I have the problem that it don't extract the dxfs from all sub-assembly but only the sheets of the main assembly.
how can I solve?

Code:

Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument
Dim oAsmDoc As AssemblyDocument
Dim ItemQuantiy As String
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 stored value
ItemQuantity = iProperties.Value("Summary", "Keywords")

ItemQuantity = InputBox("Enter the quantity.", "Quantity", ItemQuantity)
If ItemQuantity = "" Then Return

'store the value
iProperties.Value("Summary", "Keywords") = ItemQuantity

'Get user input
RUsure = MessageBox.Show( _
"This will create a DXF file for all of the asembly 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=2018" & _
			"& RebaseGeometry = True" & _
			"& OuterProfileLayer = 0" & _
			"& OuterProfileLayerColor = 0 ;0 ;0" & _
			"& InteriorProfilesLayer = 0" & _
			"& InteriorProfilesLayerColor = 0 ;0 ;0" & _
			"& InvisibleLayers = 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_DOWN ;DIGI_MARKER_TOOL_1 ;DIGI_MARKER_TOOL_2 ;" & _
				"IV_BEND ;IV_BEND_DOWN "

			Dim oQty As String = oRow.ItemQuantity
			oQty = oQty * ItemQuantity

			Dim ShortName As String = "Qty-" & oQty & "_" & 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

Thx 

 

0 Likes
502 Views
7 Replies
Replies (7)
Message 2 of 8

Cadkunde.nl
Collaborator
Collaborator

I would suggest going through the assembly like this:

https://modthemachine.typepad.com/my_weblog/2009/03/accessing-assembly-components.html

 

I see you are going through the bill of material.

Which BoM you go through is depending on the amount of Bom views that are disabled:

 

Dim oBOMView As BOMView = oBOM.BOMViews.Item(oBOM.BOMViews.Count)

 

So if Model Data, Structured and Parts Only tabs (= 3 tabs) are all enabled. you will go through 'parts only'  (bomviews.count = 3)

You will get different result I think whether you go through Structured or Parts Only.

 

If you want to force it to go through parts only:

 

Dim oBOMView As BOMView = oBOM.BOMViews.Item(3)

0 Likes
Message 3 of 8

raith-mb
Advocate
Advocate

You can change your Line 50:

from:  oBOM.StructuredViewEnabled = True

to:      PartsOnlyViewEnabled = True

 

Regards

Roland

0 Likes
Message 4 of 8

guido_maniglia
Enthusiast
Enthusiast

Dont' work

0 Likes
Message 5 of 8

guido_maniglia
Enthusiast
Enthusiast


@Cadkunde.nl wrote:

I would suggest going through the assembly like this:

https://modthemachine.typepad.com/my_weblog/2009/03/accessing-assembly-components.html

 

I see you are going through the bill of material.

Which BoM you go through is depending on the amount of Bom views that are disabled:

 

Dim oBOMView As BOMView = oBOM.BOMViews.Item(oBOM.BOMViews.Count)

 

So if Model Data, Structured and Parts Only tabs (= 3 tabs) are all enabled. you will go through 'parts only'  (bomviews.count = 3)

You will get different result I think whether you go through Structured or Parts Only.

 

If you want to force it to go through parts only:

 

Dim oBOMView As BOMView = oBOM.BOMViews.Item(3)




Errore alla riga 51 nella regola: Regola0, nel documento: stack_rev1.iam

Parametro non corretto. (Eccezione da HRESULT: 0x80070057 (E_INVALIDARG))
0 Likes
Message 6 of 8

denis.semeniuc
Advocate
Advocate

Hi, 

 

I also use this code. 

It dont work if the level of detail not Master.

Add this code in the start of main code:

 

 ' Activate level of detail Master
Dim oLOD As LevelOfDetailRepresentation  
Dim oAsmCompDef As ComponentDefinition  = oDoc.ComponentDefinition 
Try 
oLOD = oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Item("XX").Activate(True)
Catch
End Try

 Replace "XX" by your name of master level of detail.

 

CDT.

0 Likes
Message 7 of 8

guido_maniglia
Enthusiast
Enthusiast

@denis.semeniuc wrote:

Hi, 

 

I also use this code. 

It dont work if the level of detail not Master.

Add this code in the start of main code:

 

 ' Activate level of detail Master
Dim oLOD As LevelOfDetailRepresentation  
Dim oAsmCompDef As ComponentDefinition  = oDoc.ComponentDefinition 
Try 
oLOD = oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Item("XX").Activate(True)
Catch
End Try

 Replace "XX" by your name of master level of detail.

 

CDT.



 Replace "XX" by your name of master level of detail.

can you give me an example? I don't understand what they are

0 Likes
Message 8 of 8

denis.semeniuc
Advocate
Advocate

Hi, 

your code whith the add in for lever of detail:

 

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

' Activate level of detail Master
Dim oLOD As LevelOfDetailRepresentation  
Dim oAsmCompDef As ComponentDefinition  = oDoc.ComponentDefinition 
Try 
oLOD = oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Item("XX").Activate(True)
Catch
End Try

'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 stored value
ItemQuantity = iProperties.Value("Summary", "Keywords")

ItemQuantity = InputBox("Enter the quantity.", "Quantity", ItemQuantity)
If ItemQuantity = "" Then Return

'store the value
iProperties.Value("Summary", "Keywords") = ItemQuantity

'Get user input
RUsure = MessageBox.Show( _
"This will create a DXF file for all of the asembly 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=2018" & _
			"& RebaseGeometry = True" & _
			"& OuterProfileLayer = 0" & _
			"& OuterProfileLayerColor = 0 ;0 ;0" & _
			"& InteriorProfilesLayer = 0" & _
			"& InteriorProfilesLayerColor = 0 ;0 ;0" & _
			"& InvisibleLayers = 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_DOWN ;DIGI_MARKER_TOOL_1 ;DIGI_MARKER_TOOL_2 ;" & _
				"IV_BEND ;IV_BEND_DOWN "

			Dim oQty As String = oRow.ItemQuantity
			oQty = oQty * ItemQuantity

			Dim ShortName As String = "Qty-" & oQty & "_" & 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

 

Need to replase XX by "Name of Maste Level ofDetails" in your assambly. 

oLOD = oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Item("XX").Activate(True)

My inventor is in Franch, is not the same name. 

denissemeniuc_0-1676903040216.png

Cdt.

 

 

 

 

 

 

 

 

0 Likes