BOM renumber using the renumber items function.

BOM renumber using the renumber items function.

dillan.swart
Explorer Explorer
495 Views
5 Replies
Message 1 of 6

BOM renumber using the renumber items function.

dillan.swart
Explorer
Explorer

Hello everyone, I'm looking for a script that can replicate the functionality of the 'Renumber Items' button in a Bill of Materials (BOM). I need the script to locate the BOM within an IDW file and make the necessary edits. Specifically, if the BOM spans multiple pages, I want the script to ensure that item numbering continues from the previous page, rather than restarting at 1. Also if the BOM has been renumbered any balloons must change with it. I can't seem to get this and might not be advanced enough with logic to get this working Is this achievable?

 

2023-09-27 12_35_59-Autodesk Inventor Professional 2024.png

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

gerrardhickson
Collaborator
Collaborator

Yes, this is possible. Share the code that you've tried so far and we can take a look.

Keep in mind that what you see on the drawings is a PartsList object not a BOM - the BOM belongs to the AssemblyDocument.

 

There are a couple of things you'll need to deal with, like what happens if one part is displayed on the parts list over multiple pages? Presumably, you'll let the first number it gets take precedence.

 

Here's how I would handle it:

  • Create an integer variable (lets call it X1) - this will be your number that increments.
  • Get a reference to the BOM (not partslist) from your drawing.
  • Set the number for every row to 'X' - this indicates that the number needs to be changed.
  • Then - iterate through each PartsListRow in each PartsList on each Drawing (and/or sheet).
    • If the number for the PartsListRow is 'X' then, set update the number to be your integer variable (X1), otherwise, skip it because it has already been numbered.
    • Increment the integer variable (X1=X1+1)

Hope that helps.

 

 

 

0 Likes
Message 3 of 6

dillan.swart
Explorer
Explorer

This is what I had, but by the sounds of it I'm way off. Could you possibly help?

 

Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
Dim oPartsList As PartsList
oPartsList = oDrawDoc.ActiveSheet.PartsLists.Item(1)
 
i = MessageBox.Show("Do you wish to Renumber BOM?", "My iLogic Dialog", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1) 
If i = vbYes Then
Trace.WriteLine ("INV - Transfer; User Selection; Do you wish to Renumber? - YES")
'Renumbers & Sort BOM
oPartsList.Renumber   
 
Trace.WriteLine ("INV-ExternalRule - Renumber BOM#")
Else If i = vbNo 
Trace.WriteLine ("INV -  Transfer; User Selection; Do you wish to change Renumber BOM? - NO")
End If
0 Likes
Message 4 of 6

gerrardhickson
Collaborator
Collaborator

Help guide you through or just write it for you?

Sub Main()
    Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument
    Dim oPL As PartsList
    Dim oPLR As PartsListRow
    Dim oBOM As BOM
    Dim oBR As BOMRow
    Dim oS As Sheet
    Dim X1 As Integer
    
    ' SET ITEM NUMBER FOR ALL ROWS TO BE 'X'
    oBOM = oDoc.ActiveSheet.PartsLists(1).ReferencedDocumentDescriptor.ReferencedDocument.ComponentDefinition.BOM
    
    For Each oBR In oBOM.BOMViews(2).BOMRows	'<== YOU'LL NEED TO SET THIS TO 'BOMViews(2) OR (3) DEPENDING ON WHETHER YOU USED STRUCTURED OR PARTS ONLY BOM VIEWS.
        oBR.ItemNumber = "X"
    Next oBR
    oDoc.Update
    
    'NOW ITERATE THROUGH EACH PARTS LIST ON EACH SHEET AND SET IT TO A NUMBER
    X1 = 1
    For Each oS In oDoc.Sheets
        For Each oPL In oS.PartsLists
            For Each oPLR In oPL.PartsListRows
                If oPLR.Item(1).Value = "X" Then
                    oPLR.Item(1).Value = X1
                    X1 = X1 + 1
                    
                End If
            Next oPLR
            oPL.SaveItemOverridesToBOM
        Next oPL
    Next oS
End Sub

 

0 Likes
Message 5 of 6

dillan.swart
Explorer
Explorer

This is excellent! However, I've noticed one issue: it tallies all the items on your initial Bill of Materials (BOM). Subsequently, when I split it, the tool continues counting, incorporating the split items into the previous BOM. For instance, if you initially had 10 items on your BOM, after splitting it in half and running the rule, it counts items 1-5 on sheet 1 and then 11-15 on sheet 2.

Additionally, I'm curious if there's a way to configure it so that you don't need to be on the same sheet as the BOM to execute the rule. Instead, could it search through the IDW for the BOM and then execute the rule?

 

This is great learning experience. Thank you very much man.

0 Likes
Message 6 of 6

gerrardhickson
Collaborator
Collaborator

Ok great, I'm sure you can figure out how to resolve those issues.

Make sure you understand what each line of the code does, and go from there.


I'll even give you a hint:

  • To restart the numbering, you need to reset the count incrementer (X1=1) for each parts list - so move line 19 somewhere that makes more sense.
  • To make it so you don't need to be on the same sheet as the Parts list, you need to update Line 11 so that it looks through each sheet until it find one. 
0 Likes