How I can set the item number with ilogic?

How I can set the item number with ilogic?

Anonymous
Not applicable
2,682 Views
6 Replies
Message 1 of 7

How I can set the item number with ilogic?

Anonymous
Not applicable

Hello,

 

I like to set the item names of my parts in my assembly with a ilogic code.

I have an assembly with a part and I know the part number. Now I like to set the item number of this part with ilogic.

like:
part number = Screw22

 

'(phantasy code)

item.number(" Screw22")=5

 

and now the item number of the Screw22 is 5.

0 Likes
Accepted solutions (1)
2,683 Views
6 Replies
Replies (6)
Message 2 of 7

JhoelForshav
Mentor
Mentor

@Anonymous 

See example below. You can choose which bom view you want to change the item number in.

 

Dim oBOM As BOM = ThisAssembly.Document.ComponentDefinition.BOM
For Each oBOMRow As BOMRow In oBOM.BOMViews.Item("Structured").BOMRows
'For Each oBOMRow As BOMRow In oBOM.BOMViews.Item("Parts Only").BOMRows
If oBOMRow.ComponentDefinitions(1).Document.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value = "Screw22"
	oBOMRow.ItemNumber = 5
End If
Next
Message 3 of 7

Anonymous
Not applicable

Thanks for the answere.

This looks good for me, but if i try this rule in my assembly i get this error message: 

 

 

HRESULT: 0x80070057 (E_INVALIDARG)


0 Likes
Message 4 of 7

JhoelForshav
Mentor
Mentor

Hi @Anonymous 

Maybe the BOM view isn't enabled?

Try this to make sure it is first

Dim oBOM As BOM = ThisAssembly.Document.ComponentDefinition.BOM
'Make sure the views are enabled
oBOM.StructuredViewEnabled = True
oBOM.PartsOnlyViewEnabled = True
'---------------------------------

For Each oBOMRow As BOMRow In oBOM.BOMViews.Item("Structured").BOMRows
'For Each oBOMRow As BOMRow In oBOM.BOMViews.Item("Parts Only").BOMRows
If oBOMRow.ComponentDefinitions(1).Document.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value = "Screw22"
	oBOMRow.ItemNumber = 5
End If
Next
Message 5 of 7

Anonymous
Not applicable

it's still not works. 
I uploaded a screencast.
But this week I only on my personal computer at home, maybe this can work at my place of work.

 
0 Likes
Message 6 of 7

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @Anonymous 

Maybe it's a language thing?

Have you tried with the german names for the BOM-views?

Dim oBOM As BOM = ThisAssembly.Document.ComponentDefinition.BOM
'Make sure the views are enabled
oBOM.StructuredViewEnabled = True
oBOM.PartsOnlyViewEnabled = True
'---------------------------------

For Each oBOMRow As BOMRow In oBOM.BOMViews.Item("Strukturiert").BOMRows
'For Each oBOMRow As BOMRow In oBOM.BOMViews.Item("Nur Bauteile").BOMRows
If oBOMRow.ComponentDefinitions(1).Document.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value = "Screw22"
	oBOMRow.ItemNumber = 5
End If
Next

Check my spelling, It was difficult to read the names due to the resolution of the screencast:)

Message 7 of 7

Anonymous
Not applicable

you are a genius!

with the german names it works perfectly.

Thank you very much