Resort components order in assembly BOM

Resort components order in assembly BOM

aries.1482
Enthusiast Enthusiast
466 Views
5 Replies
Message 1 of 6

Resort components order in assembly BOM

aries.1482
Enthusiast
Enthusiast

Hi,

I have a main-assembly with a sub-assembly and parts. In main-assembly BOM, I want to show all components in sub-assembly so I choose All Levels in Structured Properties. It's OK. But the issue is the order of those components in main-assembly BOm is not the same in sub-assembly BOM. For example:

Sub-assembly: SubPart 1 as Item 1, SubPart 2 as Item 2

Main-assembly: SubPart 1 as Item 1.2; SubPart 2 as Item 1.1

(see attach below)

2.jpg1.jpg

Is there any code to resort all components in main-assembly BOM so they have the same order in sub-assembly BOM?

Plz help me. Thank you.

0 Likes
467 Views
5 Replies
Replies (5)
Message 2 of 6

JohnKHouston
Advocate
Advocate

Try using the 'Sort By' option. It's the button up at the top with the A->Z icon. It should allow you to sort by any column that you have in your BOM. No code required...  🙂

0 Likes
Message 3 of 6

aries.1482
Enthusiast
Enthusiast

Thanks for reply.

I know option "Sort by", but part number is not like in the example, it is random character so I can't sort by part number.

0 Likes
Message 4 of 6

JohnKHouston
Advocate
Advocate

Gotcha, I was too literal because of your example. Good luck, hope you find a solution!

0 Likes
Message 5 of 6

Ralf_Krieg
Advisor
Advisor

Hello

 

There's AFAIK no way to move the BOM rows.

You can try to copy the item numbers from subassembly BOM to main assembly BOM and order by item number. This should "reorder" the BOM rows in main assembly BOM. After this you should renumber the main assembly.

Below is a VBA example. Don't know if it works 100%.

Option Explicit

Private Sub BOMReorder()

Dim oApp As Inventor.Application
Set oApp = ThisApplication

Dim oAssDoc As AssemblyDocument
Set oAssDoc = oApp.ActiveDocument

Dim oBOM As BOM
Set oBOM = oAssDoc.ComponentDefinition.BOM

If oBOM.StructuredViewEnabled = False Then Exit Sub
If oBOM.StructuredViewFirstLevelOnly = True Then Exit Sub

Dim oBOMView As BOMView
Set oBOMView = oBOM.BOMViews(2)

Dim oBOMRows As BOMRowsEnumerator
Set oBOMRows = oBOMView.BOMRows

Dim oBOMRow As BOMRow
For Each oBOMRow In oBOMRows
    If Not oBOMRow.ChildRows Is Nothing Then
        Call TraverseBOM(oBOM, oBOMRow)
    End If
Next

Call oBOMView.Sort("Item")
Call oBOMView.Renumber

End Sub

Private Sub TraverseBOM(ByRef oBOM As BOM, ByRef oBOMRow As BOMRow)

Dim oRefedDoc As AssemblyDocument
Set oRefedDoc = oBOMRow.ComponentDefinitions(1).Document

Dim oSubBOM As BOM
Set oSubBOM = oRefedDoc.ComponentDefinition.BOM

oSubBOM.StructuredViewEnabled = True
oSubBOM.StructuredViewFirstLevelOnly = False

Dim oSubBOMView As BOMView
Set oSubBOMView = oSubBOM.BOMViews(2)

Dim oBOMRows As BOMRowsEnumerator
Set oBOMRows = oBOMRow.ChildRows

Dim oChildRow As BOMRow
Dim oSubChildRow As BOMRow
Dim i As Integer

For Each oChildRow In oBOMRows
    For i = 1 To oSubBOMView.BOMRows.Count
        If oSubBOMView.BOMRows(i).ReferencedFileDescriptor.FullFileName = oChildRow.ReferencedFileDescriptor.FullFileName Then
            oChildRow.ItemNumber = oSubBOMView.BOMRows(i).ItemNumber
        End If
    Next
    
    If Not oChildRow.ChildRows Is Nothing Then
        Call TraverseBOM(oBOM, oChildRow)
    End If
Next

End Sub

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 6 of 6

aries.1482
Enthusiast
Enthusiast

Thank you, I'll try this.

0 Likes