Iterate Structured BOMView

<?xml encoding=”UTF-8″>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

Comments

7 responses to “Iterate Structured BOMView”

  1. Sowjanya Avatar
    Sowjanya

    hi
    I tried with the above macro, but in quantity (qty) column, I got member count error. please help.

  2. Sowjanya Avatar
    Sowjanya

    sorry forgot to mention, that I tried this VBA code in Autodesk Inventor 2013, to get Indented BOM table in drawing.

  3. HI,
    Could you please log a question on the forum with more details, preferably with a small, non-confidential set of documents added that could be used to reproduce the issue?
    http://forums.autodesk.com/t5/Inventor-Customization/bd-p/120
    Thank you,
    Adam

  4. Gilberto Avatar
    Gilberto

    Hello friends.
    How could I import to Excel my “Inventor User Defined Properties”?
    I’ve got imported the “Design Tracking Properties”, “Inventor Summary Information”, etc., but the custom properties from teh model object I haven’t.
    Could you, please help me on this issue?

  5. Hi,
    What exact help do you need? You can reach the properties for any of the property sets you want.
    Could you please ask this question on the forum instead and clarify what exact problem you are running into? It’s much easier to have a discussion there than in the comments section here.
    Thank you,
    Adam

  6. Horacio Estrada Avatar
    Horacio Estrada

    Hello,
    Thank you very much for sharing this information. It will be very useful.
    When I prepare my BOMs, I normally sort the “Structured” BOM by Part Number (ascending) and then I renumber it. Unfortunately in the API the index of each row Item doesn’t follow the sorting and renumbering, therefore the row INDEX usually doesn’t match the ITEM NUMBER.
    What I would really like to do is to traverse the entire Structured BOM according to the sorting and renumbering that I choose to do. Is there any recommendation you can shared with me for getting this accomplished.
    Thank you

  7. Dear Adam,
    This code just follow Model Data (Hierarchy). If we have sorting the data in the Structured BOM, the result isn’t followed or the result isn’t corret.
    Here’s the sample.
    1 Bottom VC
    1.1 Base
    1.2 Left Side Cover
    1.3 Right Side Cover
    1.4 Front Cover
    1.5 Back Cover
    4 Top Cover
    2 Hinge
    2.1 Bottom Hinge
    2.2 Top Hinge
    2.3 Hinge Shaft
    5 ISO 4762 – M5 x 20
    6 ISO 4762 – M5 x 12
    3 Handle
    3.1 Bracket Handle
    3.2 Handle Shaft

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading