Public Sub IterateRows _
(oBOMRows As BOMRowsEnumerator, indent As Integer)
Dim oBOMRow As BOMRow
For Each oBOMRow In oBOMRows
For i = 1 To oBOMRows.Count
' rename ItNumber
Dim ItemNumber As String
If InStrRev(oBOMRows.Item(i).ItemNumber, ".") > 0 Then
ItemNumber = Right$(oBOMRow.ItemNumber, InStrRev(oBOMRow.ItemNumber, ".") - 1)
Else
ItemNumber = oBOMRow.ItemNumber
End If
If ItemNumber = i Then
' Let's only get the first definition
' It would only be more than one if rows were merged
Dim oDef As ComponentDefinition
Set oDef = oBOMRow.ComponentDefinitions(1)
Dim partNumber As String
partNumber = oDef.Document.PropertySets( _
"{32853F0F-3444-11D1-9E93-0060B03C1CA6}")("Part Number").Value
Debug.Print Tab(indent); oBOMRow.ItemNumber + " " + partNumber
If Not oBOMRow.ChildRows Is Nothing Then
Call IterateRows(oBOMRow.ChildRows, indent + 1)
End If
Exit For
End If
Next
Next
End Sub
Public Sub IterateThroughStructuredBOM()
Dim oAsm As AssemblyDocument
Set oAsm = ThisApplication.ActiveDocument
Dim oBOM As BOM
Set oBOM = oAsm.ComponentDefinition.BOM
' Make sure it's enabled
oBOM.StructuredViewEnabled = True
oBOM.StructuredViewFirstLevelOnly = False
Dim oBOMView As BOMView
Set oBOMView = oBOM.BOMViews(2)
Call IterateRows(oBOMView.BOMRows, 1)
End Sub