Export Structured BOM view with All Levels

Export Structured BOM view with All Levels

tech
Enthusiast Enthusiast
1,988 Views
4 Replies
Message 1 of 5

Export Structured BOM view with All Levels

tech
Enthusiast
Enthusiast

Hi all.

 

I am looking for a way to export the structured BOMview from Inventor to either Excel or Word. That’s all good and I can do that but I struggle to find a way to include “All Levels” of the structured BOM view. At the moment I use a “For Each item in BOMview” loop to cycle through the BOMView items.

I have also set the StructuredViewFirstLevelOnly property to False. The For Each  loop does not pick up any items inside sub-assemblies.

What would be a nice way to drill down and get an item output like this:

 

1

2

2.1

2.1

3

4

5

5.1

5.2

 

Etc

 

Any pointers?

0 Likes
1,989 Views
4 Replies
Replies (4)
Message 2 of 5

adam.nagy
Autodesk Support
Autodesk Support

Happy New Year!

 

You can iterate through the ChildRows in order to do that. The following VBA code shows how to do that in an assembly document

Sub ListBomItems()
    Dim asm As AssemblyDocument
    Set asm = ThisApplication.ActiveDocument
    
    Dim b As BOM
    Set b = asm.ComponentDefinition.BOM
    
    b.StructuredViewEnabled = True
    
    Dim bv As BOMView
    Set bv = b.BOMViews("Structured")
    
    Call ListItems(bv.BOMRows, 0)
End Sub

Sub ListItems(rows As BOMRowsEnumerator, indent As Integer)
    Dim row As BOMRow
    For Each row In rows
        Debug.Print Spc(indent); row.ItemNumber
        If Not row.ChildRows Is Nothing Then
            Call ListItems(row.ChildRows, indent + 2)
        End If
    Next
End Sub

I hope this helps.

 

Cheers,



Adam Nagy
Autodesk Platform Services
0 Likes
Message 3 of 5

skyngu
Collaborator
Collaborator

it can be used. but the order is wrong. look something like this:

 

2
3
1
  1.1
  1.2
  1.3

Autodesk Inventor Professional 2019
0 Likes
Message 4 of 5

Raider_71
Collaborator
Collaborator

Hi yes that’s because the BOM has been reordered in Inventor. When exporting using a For loop it does not start with the top row of the BOM but it looks at the Row ID. So the first Item you inserted into the assembly will always be row 1 and will be exported first even if it has been reordered to sit lower down in the BOM. This is my explanation of what’s happening.

I sort my data using the Excel API. The problem you now have is that you have to cater for multiple decimal separators like in the case of: 2.1.3 for instance... There are many ways to do this I found on the net. If you need more info let me know. What’s your application?

 

Cheers

Pieter

 

0 Likes
Message 5 of 5

skyngu
Collaborator
Collaborator

thanks. I usually export bom in excel sheet directly. then arrange column order a little bit.

 

oStructuredBOMView.Export sTempPath, kMicrosoftExcelFormat, "Structured"

 

I point that out because I am trying to find the best way to handle bom export and update.

Autodesk Inventor Professional 2019
0 Likes