Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Renumber Structured BOM with gap in numbering based on part number of individual items

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
claudio.ibarra
310 Views, 5 Replies

Renumber Structured BOM with gap in numbering based on part number of individual items

I'm trying to generate a script that sorts and renumbers an assembly BOM, based on the iProperty for part number with each row.

The part numbers for "Make" items are structured differently than those for "Buy" items. "Make Items" part numbers start with 3 numbers, then have "-D-M" and then three or sometimes four numbers after that. All other part numbers are "buy" items.

I'd like to run the script and have both "Make" and "Buy" items sorted by part number within their groups, but then re-numbered so the "Make" items are 1-99 and the "Buy" items are 100-[end]. There will never be 99 "make" items in an assembly, so I think 100 is enough. 


Then I think I'm supposed to save the changed Structured BOM item numbers back to the BOM, but I'm not sure. 

The goal is to have a numerical separation in the parts list numbers, so you see a balloon value less than 100, you know it's a "make" item, without having to ask anyone to manually take care of numbering.

Is this a challenging script to write?

Tags (3)
Labels (3)
5 REPLIES 5
Message 2 of 6

You can start from code mentioned in this post if you want to sort BOM rows.  Or you can use two counters for two groups of components.

 

 

Sub Main()
    Dim asm As AssemblyDocument = ThisDoc.Document
    Dim bomView As BOMView = asm.ComponentDefinition.BOM.BOMViews(2) 'Structured BOMView must be enabled

    SortBomView(bomView)
End Sub

Private Sub SortBomView(bomView As BOMView)
    Dim makeCounter = 1
    Dim buyCounter = 100

    For Each bomRow As BOMRow In bomView.BOMRows
        Dim rowDocument As Document = bomRow.ComponentDefinitions(1).Document
        Dim partNumber As String = rowDocument.PropertySets("{32853F0F-3444-11D1-9E93-0060B03C1CA6}")("Part Number").Value.ToString()

        If (IsMake(partNumber)) Then
            bomRow.ItemNumber = makeCounter
            makeCounter += 1
        Else
            bomRow.ItemNumber = buyCounter
            buyCounter += 1
        End If
    Next

End Sub

Private Function IsMake(partNumber As String) As Boolean
    'Implement your detection of Make part here
    Return partNumber.Substring(3).StartsWith("-D-M")
End Function

 

 

 

Message 3 of 6

This works, but I don't understand it. What part of it sorts by part number? Please help me understand the sorcery! 

Message 4 of 6

This is not a sorcery 😀

Function IsMake splits BOMRows to two groups. Each of them has its own counter (makeCounter and buyCounter)

When you use last value from counter (lines 17 and 20), its value are increased by 1 (lines 18 and 21).

Order of BOMRows in each group stay unchanged.

 

Message 5 of 6

Is it possible to make this separation like it does now, and then sort both lists, so that the make and buy items are sorted by their part numbers after they're separated? So it'll be the "Make" numbers in order of part number starting with 1, 2, 3; and then the "Buy" numbers in order of part number, starting with "100, 101, 102, etc."

Message 6 of 6

You can see my mentioned post, where it is shown. 

Before renumbering you can sort BOMRows by PartNumber

After renumbering you can sort BOMRows by Item number

'Finally sort the rows by ItemNumber
'bomView.Sort("Položka") 'Czech
bomView.Sort("Item") 'English

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report