Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

BOMView.Renumber

martinhoos
Advocate

BOMView.Renumber

martinhoos
Advocate
Advocate

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

0 Likes
Reply
Accepted solutions (1)
2,007 Views
15 Replies
Replies (15)

rhasell
Advisor
Advisor

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")
Reg
2025.2
0 Likes

martinhoos
Advocate
Advocate

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

 

 

0 Likes

rhasell
Advisor
Advisor

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")
Reg
2025.2
0 Likes

martinhoos
Advocate
Advocate

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

 

0 Likes

rhasell
Advisor
Advisor

hi

 

Hopefully someone can jump in here, I have to leave the office and can only get back to it tomorrow.

:disappointed_face:

 

Reg
2025.2
0 Likes

sajith_subramanian
Autodesk Support
Autodesk Support

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
0 Likes

rhasell
Advisor
Advisor

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.

 

Reg
2025.2
0 Likes

rhasell
Advisor
Advisor
Accepted solution

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")
Reg
2025.2

J_Dumont
Advocate
Advocate

Hi rhasell,

I know this is an old post but it has functionality that I need. I am able to run the code without any errors but it has no effect on the assembly BOM. Any assistance would be greatly appreciated.

0 Likes

rhasell
Advisor
Advisor

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")

 

Reg
2025.2
0 Likes

J_Dumont
Advocate
Advocate

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.

0 Likes

rhasell
Advisor
Advisor

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")
Reg
2025.2
0 Likes

J_Dumont
Advocate
Advocate

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.

 

2020-03-31_7-00-14.png

https://autode.sk/2JuuIyl

 

0 Likes

rhasell
Advisor
Advisor

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)

Reg
2025.2
0 Likes

J_Dumont
Advocate
Advocate
Thank you for all your assistance with this.

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.


0 Likes