By Adam Nagy
Here is a sample VBA code that lists some information from the Structured BOMView of an assembly:
Public Sub IterateRows _ (oBOMRows As BOMRowsEnumerator, indent As Integer) Dim oBOMRow As BOMRow For Each oBOMRow In oBOMRows ' 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 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("Structured") Call IterateRows(oBOMView.BOMRows, 1) End Sub
It prints out something like this:
1 SubAsm1 1.1 Part11 1.2 Part12 2 SubAsm2 2.1 Part21 2.2 Part22