Occurrence Name from BOMRow

Occurrence Name from BOMRow

meck
Collaborator Collaborator
1,240 Views
5 Replies
Message 1 of 6

Occurrence Name from BOMRow

meck
Collaborator
Collaborator

I am trying to get the occurrence number of a part or sub-assembly from an assembly Bill of Materials. I am iterating through the rows of the Bill of Materials as follows...

 

For i = 1 To oBOMRows.Count
' Get the current row.
Dim oRow As Inventor.BOMRow
oRow = oBOMRows.Item(i)

'Set a reference to the primary ComponentDefinition of the row
Dim oCompDef As Inventor.ComponentDefinition
oCompDef = oRow.ComponentDefinitions.Item(1)

 

next

 

From this point I am completely stumped. I have tried everything I can think of to get the occurrence of the part from the oRow object. I either get an error if the oRow is a part, or the sub-assembly's parts, but not the sub-assembly itself.

 

Please somebody help.

Thanks in Advance

Meck

 

 

Mike Eck
Master Drafter/ CAD Programmer
Using Inventor 2018
0 Likes
Accepted solutions (1)
1,241 Views
5 Replies
Replies (5)
Message 2 of 6

TomaszDąbrowski
Enthusiast
Enthusiast

In my opinion just add this lines to your code (before next)

Dim x As String = oRow.TotalQuantity
Dim y As String = oCompDef.Document.displayname
MsgBox("Quantity of " & y & " equals " & x)
0 Likes
Message 3 of 6

meck
Collaborator
Collaborator

Thanks for the reply TomaszDąbrowski,

 

 The code you provides returns the file name. I am looking for the occurrence number as it relates to a row of the Bill of Material. This is the name as it appears in the assembly model's browser. For example: ABC123:1 

Because is it possible to have ABC123:1, ABC123:2, ABC123:3 and so on, I need to know which instance oRow is referencing.

 

Thanks

Meck

Mike Eck
Master Drafter/ CAD Programmer
Using Inventor 2018
0 Likes
Message 4 of 6

Michael.Navara
Advisor
Advisor
Accepted solution

You can't get occurrence directly from BomRow because BomRow doesn't reference only one occurrence. But you can look for all occurrences bz this code fragment

Dim asm As AssemblyDocument = ThisDoc.Document
Dim asmOccurrences = asm.ComponentDefinition.Occurrences
Dim bomView As BOMView = asm.ComponentDefinition.BOM.BOMViews(2)

For Each bomRow As BOMRow In bomView.BOMRows
    Logger.Debug(bomRow.ItemNumber)
    For Each compDef As ComponentDefinition In bomRow.ComponentDefinitions
        Dim occurrences = asmOccurrences.AllLeafOccurrences(compDef)
        For Each occ As ComponentOccurrence In occurrences
            Logger.Debug(vbTab & occ.Name)
        Next
    Next
Next
Message 5 of 6

meck
Collaborator
Collaborator

Thanks Michael! Just what I was looking for.

Mike Eck
Master Drafter/ CAD Programmer
Using Inventor 2018
0 Likes
Message 6 of 6

meck
Collaborator
Collaborator

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
0 Likes