Change item number of a specific component in BOM

Change item number of a specific component in BOM

Darrell.johnson
Enthusiast Enthusiast
835 Views
4 Replies
Message 1 of 5

Change item number of a specific component in BOM

Darrell.johnson
Enthusiast
Enthusiast

Hello,

 

is it possible to change the item number of a specific component in an assembly file?

 

Dim ThisDoc As Document = ThisApplication.ActiveDocument
Dim oComps As ComponentOccurrences = ThisDoc.ComponentDefinition.Occurrences
Dim oComp As ComponentOccurrence

For Each oComp In oComps
	If oComp.Name.Contains("xyz")
		'change the item number
	End If
Next

 

0 Likes
Accepted solutions (1)
836 Views
4 Replies
Replies (4)
Message 2 of 5

Ralf_Krieg
Advisor
Advisor

Hello

 

I think you must start in the BOM and search per row to find your occurrence. The item number is not stored in the occurrence object.

Wich Inventor version?

Structured or Parts only BOM View?

What if the item number is already in use by another occurrence?

Why do you need an explicit number for this occurrence?


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

Darrell.johnson
Enthusiast
Enthusiast

Hello thank you for your reply,

 

- I'm using Inventor Version 2021

- Structered BOM view

- I think that's not the case in this scenario

- I need to renumber the components by their name, sorting doesn't work for me in this case

 

Screenshot 2021-04-26 082708.png

for example: the component "41-00639-1-0" needs to be renumbered from 176 to 1; "5041-0009" from 178 to 2; "41-02943-1-0" from 174 to 3.

0 Likes
Message 4 of 5

dutt.thakar
Collaborator
Collaborator
Accepted solution

@Darrell.johnson 

 

Can you try this code ? it actually checks the name of the part, if it contains a certain characters, it changes it's item number, you just need to be aware that, it does not do anything if two components has the same item number, you will see it highlighted in yellow in BOM.

 

Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition

Dim oBOM As BOM = oDef.BOM
Dim oBOMView As BOMView
oBOMView = oBOM.BOMViews.Item("Structured")

Dim bRows As BOMRowsEnumerator = oBOMView.BOMRows

For Each bRow In bRows
	Dim rDoc As Document
	rDoc = bRow.ComponentDefinitions.Item(1).Document
	If rDoc.DisplayName.Contains("PolyGon")
		bRow.ItemNumber = 1
	End If
Next

 

Hope this will help you.

If this answer has solved your problem please ACCEPT SOLUTION and hit like if you found it helpful..!


Regards,
Dutt Thakar
LinkedIn
Message 5 of 5

Darrell.johnson
Enthusiast
Enthusiast

Thank you very much, this code works perfectly.

0 Likes