Inventor 2022, BOM Export component definition Issues

Inventor 2022, BOM Export component definition Issues

m.vankeulenVSCLM
Observer Observer
217 Views
1 Reply
Message 1 of 2

Inventor 2022, BOM Export component definition Issues

m.vankeulenVSCLM
Observer
Observer

Hello Everyone, 

 

A couple of years ago we wrote an iLogic code to export the BOM from the assembly model to a template Excel. 

Earlier this year we updated to 2022 and we've recently been using model states, which have been giving error with the export code. 

 

If we have a "normal" assembly the code works fine. Even if, within that assembly, a subassembly is used with a model state.

If the main assembly has different model states however, the code fails. 

It specifically fails in the Public sub, with component definitions of the BOMRow items. (Line 15)

 

If we change Line 101 with the addition .FactoryDocument the code accepts the component definitions but gives an error at PropertySets. (Line 18) 

And the code doesn't work anymore for assemblies without model states. (also error on line 18)

 

I hope my issue is clear, and apologies for the long code:

 

 

 

		Call QueryBOMRowProperties(oBOMView.BOMRows, sNewBOM, iCurrRow)
		
Public Sub QueryBOMRowProperties(oBOMRows As BOMRowsEnumerator, JobSpreadsheetName As String, iCurrRow As Integer)
' Iterate through the contents of the BOM Rows
	Static CurrentRow As Integer = iCurrRow
	
	Dim i As Long
	For i = 1 To oBOMRows.Count
		
' Get current row
		Dim oRow As BOMRow
		oRow = oBOMRows.Item(i)
		
		Dim oCompDef As ComponentDefinition
		oCompDef = oRow.ComponentDefinitions.Item(1)

		Dim oPropSets As PropertySets
		oPropSets = oCompDef.Document.PropertySets
		
' File property shortcuts
		oDesignTrackingPropertySet = oPropSets.Item("Design Tracking Properties")		'Project tab shortcut
		oInventorSummaryPropertySet = oPropSets.Item("Inventor Summary Information")		'Summary tab shortcut
		oCustomPropertySet = oPropSets.Item("Inventor User Defined Properties")			'Custom tab shortcut
		
' Get the file properties that are required
		oItemNumberProperty = oRow.ItemNumber
		oPartNumProperty = oDesignTrackingPropertySet.Item("Part Number")
		oDescripProperty = oDesignTrackingPropertySet.Item("Description")
		oTitleProperty = oInventorSummaryPropertySet.Item("Title")
	
		' Recursively iterate child rows if present
		If Not oRow.ChildRows Is Nothing Then
			Call QueryBOMRowProperties(oRow.ChildRows, JobSpreadsheetName, CurrentRow)
		Else
		End If
		
	Next i
End Sub

 

 

 

I've been trying to get the code to work but it has been driving me crazy.

 

Any advice or referrals are greatly appreciated.

 

 

0 Likes
218 Views
1 Reply
Reply (1)
Message 2 of 2

dg2405
Advocate
Advocate

Maybe your problems are related to supressed occurrences, there you have no access to the componentdefinition-object. In such a case the Quantity of the row ist 0. Simply check for the quantity 0 of current bomrow and go to next one.

0 Likes