- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
i need a little help to renumber the bom in an assembly and sort it.
Has anyony of you a Little code for me?
Thanks in advance.
Regards from germany
Martin
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi
In my experience, sorting the BOM from the Assembly is inefficient, you can only sort with one filter (I know that you are supposed to sort with more than one, but it does not work as expected)
I find that sorting via the IDW is far better. Curtis has some code on his blog which can help.
Anyway here is some code to help you sort in the Assembly Environment.
' Set a reference to the assembly document.
' This assumes an assembly document is active.
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument
' Set a reference to the BOM
Dim oBOM As BOM
oBOM = oDoc.ComponentDefinition.BOM
' Make sure that the parts only view is enabled.
oBOM.PartsOnlyViewEnabled = True
' Set a reference to the "Parts Only" BOMView
Dim oBOMView As BOMView
oBOMView = oBOM.BOMViews.Item("Parts Only")
Call oBOMView.Sort("BOM Structure",True ,"TYPE",True ,"Stock Number",True)
'Re-Number the BOM
Call oBOMView.Renumber(1, 1)
MessageBox.Show("Done", "Sort BOM")
2025.2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thanks for reply rhasell,
i get the following message:
System.ArgumentException: Falscher Parameter. (Ausnahme von HRESULT: 0x80070057 (E_INVALIDARG))
bei System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
bei Inventor.BOMViews.get_Item(Object Index)
bei LmiRuleScript.Main()
bei Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
bei iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
I am a beginner with iLogic.
What i like to do is: To renumber the Position in an structured bom assembly, for example: 1, 2, 4, 7 renumber to 1,2,3,4
Thanks for your help.
Regards
Martin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi
I quickly had a look in the help files and made this up for you.
Have a look and see if this fixes your problem.
I changed it to sort the structured list
' Set a reference to the assembly document.
' This assumes an assembly document is active.
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument
' Set a reference to the BOM
Dim oBOM As BOM
oBOM = oDoc.ComponentDefinition.BOM
oBOM.StructuredViewFirstLevelOnly = False
oBOM.StructuredViewEnabled = True
Dim oStructuredBOMView As BOMView
oStructuredBOMView = oBOM.BOMViews.Item("Structured")
Call oStructuredBOMView.Sort("BOM Structure",True ,"TYPE",True ,"Stock Number",True)
Call oStructuredBOMView.Renumber(1, 1)
MessageBox.Show("Done", "Sort BOM")
2025.2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thanks again,
but i get a mistake message:
System.ArgumentException: Falscher Parameter. (Ausnahme von HRESULT: 0x80070057 (E_INVALIDARG))
bei System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
bei Inventor.BOM.set_StructuredViewFirstLevelOnly(Boolean )
bei LmiRuleScript.Main()
bei Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
bei iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
Regards Martin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
hi
Hopefully someone can jump in here, I have to leave the office and can only get back to it tomorrow.
![]()
2025.2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi Martin,
The code provided by @rhasell seems to work for me.
The only change I had to make to it, was that in the Sort method, I had to ensure that the column name existed.
That is, in the following line of code:
Call oStructuredBOMView.Sort("BOM Structure",True ,"TYPE",True ,"Stock Number",True)
In this case, there has to be existing columns with Titles "BOM Structure" , "TYPE" and "Stock Number", else it may throw up an error.
Regards,
Sajith

Sajith Subramanian
Autodesk Developer Network
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi
Good catch, I forgot that I use a custom field of "TYPE", did not even see that. (Been a long time since I used that code.)
Thanks.
2025.2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi
Therefore:
Try this.
' Set a reference to the assembly document.
' This assumes an assembly document is active.
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument
' Set a reference to the BOM
Dim oBOM As BOM
oBOM = oDoc.ComponentDefinition.BOM
oBOM.StructuredViewFirstLevelOnly = False
oBOM.StructuredViewEnabled = True
Dim oStructuredBOMView As BOMView
oStructuredBOMView = oBOM.BOMViews.Item("Structured")
Call oStructuredBOMView.Sort("Stock Number",True)
Call oStructuredBOMView.Renumber(1, 1)
MessageBox.Show("Done", "Sort BOM")
2025.2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi
When you mention "Assembly BOM" what are you referring to?
The above rule will sort the "Structured" list only, try the following to add Parts as well.
The rule sorts on "Stock Number" change that to suit your BOM, EG: "Part Number" or "Description"
' Set a reference to the assembly document.
' This assumes an assembly document is active.
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument
' Set a reference to the BOM
Dim oBOM As BOM
oBOM = oDoc.ComponentDefinition.BOM
oBOM.StructuredViewFirstLevelOnly = False ' Display All levels
oBOM.StructuredViewEnabled = True
oBOM.PartsOnlyViewEnabled = True
Dim oStructuredBOMView As BOMView
oStructuredBOMView = oBOM.BOMViews.Item("Structured")
' Set a reference to the "Parts Only" BOMView
Dim oPartBOMView As BOMView
oPartBOMView = oBOM.BOMViews.Item("Parts Only")
Call oStructuredBOMView.Sort("Stock Number", True)
oPartBOMView.Sort("Stock Number",True)
Call oPartBOMView.Renumber(1, 1)
Call oStructuredBOMView.Renumber(1, 1)
MessageBox.Show("Done", "Sort BOM")
2025.2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Sorry I wasn't clear. In regards to assembly BOM, I'm referencing the BOM in an assembly document. For whatever reason, the code has no effect on the sorting or renumber. I need to work with the Structured BOM and I would like to sort on, "Stock Number" and "Unit Qty" and once sorted I would like the renumber.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi
Try this, if it still does not work, then can you share a data set so that we can test it.
' Set a reference to the assembly document.
' This assumes an assembly document is active.
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument
' Set a reference to the BOM
Dim oBOM As BOM
oBOM = oDoc.ComponentDefinition.BOM
oBOM.StructuredViewFirstLevelOnly = False ' Display All levels
oBOM.StructuredViewEnabled = True
Dim oBOMView As BOMView
oBOMView = oBOM.BOMViews.Item("Structured")
' Set a reference to the "Parts Only" BOMView
Call oBOMView.Sort("Stock Number", True, "Unit QTY", True)
Call oBOMView.Renumber(1, 1)
MessageBox.Show("Done", "Sort BOM")
2025.2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Good morning.
Thank you for your response.
In testing your code it seems to work as long as I don't have a sorting done by selecting any particular column. See the attached image. The only way I am able to clear the predefined sort is to use Sort and specify any column. See attached Screencast. Once the predefined Sort is cleared the code works properly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi
Okay, I understand, I have looked for any command that will do a "Clear Sort" before you run the code, but I am unable to find it. So it is still a manual option of right click and select "clear sort".
I suggest that you check your template to ensure that there is no preset sorting in place.
On a different note, in my experience, I have found that if you are sorting with multiple columns, it is better to do a Parts List sort in a drawing, and then writing the changes back to the assembly. (This still does not override the forced sort option)
2025.2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I understand that working in the parts list seems to be easier but I need
to go through the Bom and create/edit custom UDP for parts before creating
a drawing and parts list.