So I am still trying to solve the annoying problem with iAssembly bill of materials where each member of the factory assigns different item numbers to each part no matter what the occurrence is. I thought I had this figured out until I had 2 iParts from the same factory that should be different item numbers. The iParts have matching part numbers in only a few cases. For us this would mean that we will be giving them different item numbers in the BOM. For some reason the code I am using sees the 2 iParts as the same part and gives them the same item number. If someone could clue me in as to what is happening that would be awesome! Here is the code I am using...
Private Sub SetItemNo(OccurrenceName As String, ItemNo As Integer)
'This sub sets an Item in the Bill of Materials in an assembly model to ItemNo.
'OccurrenceName is the occurrence name example: ABC123:3
' Set a reference to the assembly document.
' This assumes an assembly document is active.
Dim oDoc As Inventor.AssemblyDocument
oDoc = invApp.ActiveDocument
Dim oCompDef As Inventor.ComponentDefinition
oCompDef = oDoc.ComponentDefinition
' Set a reference to the BOM
Dim oBOM As Inventor.BOM
oBOM = oDoc.ComponentDefinition.BOM
' Set first level only BOM
oBOM.StructuredViewFirstLevelOnly = True
' Make sure that the structured view is enabled.
oBOM.StructuredViewEnabled = True
'Set a reference to the "Structured" BOMView
Dim oBOMView As Inventor.BOMView
oBOMView = oBOM.BOMViews.Item("Structured")
Dim asm As Inventor.AssemblyDocument = oDoc
Dim asmOccurrences = asm.ComponentDefinition.Occurrences
Dim bomView As Inventor.BOMView = asm.ComponentDefinition.BOM.BOMViews(2)
'Iterate through the rows of the BOM
For Each bomRow As Inventor.BOMRow In bomView.BOMRows
'Iterate through each component of the row
For Each compDef As Inventor.ComponentDefinition In bomRow.ComponentDefinitions
'A single BOM row can have multiple occurrences (Not sure how but OK)
Dim occurrences = asmOccurrences.AllLeafOccurrences(compDef)
'Get each occurence associated with the row
For Each occ As Inventor.ComponentOccurrence In occurrences
'Only process parts that are not excluded
If occ.Excluded = False Then
If occ.Name = OccurrenceName Then
bomRow.ItemNumber = ItemNo
'Exit Sub
End If
End If
Next
Next
Next
End Sub
Mike Eck
Master Drafter/ CAD Programmer
Using Inventor 2018