How to change a specific part item number in Bill of materials using Ilogic

How to change a specific part item number in Bill of materials using Ilogic

manu.marjanen
Advocate Advocate
934 Views
8 Replies
Message 1 of 9

How to change a specific part item number in Bill of materials using Ilogic

manu.marjanen
Advocate
Advocate

How to change a specific part item number in Bill of materials using Ilogic? 

For example, Now the part (part:1) item number is 10 and i would like it be to something else.

0 Likes
Accepted solutions (1)
935 Views
8 Replies
Replies (8)
Message 2 of 9

JhoelForshav
Mentor
Mentor

Hi @manu.marjanen 

Are you looking for something like this? 🙂

Dim oAsm As AssemblyDocument = ThisDoc.Document
'Pick occurrence to change item number
Dim oOcc As ComponentOccurrence = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Pick occurrence")
Dim oBOM As BOM = oAsm.ComponentDefinition.BOM
oBOM.StructuredViewEnabled = True
Dim oView As BOMView = oBOM.BOMViews.Item(2)
Dim pRow As BOMRow
'find BOM row
For Each oRow As BOMRow In oView.BOMRows
	If oRow.ComponentDefinitions(1) Is oOcc.Definition
		pRow = oRow
		Exit For
	End If
Next
If pRow Is Nothing
	'Couldnt find part in structured view. Check Parts only
	oBOM.PartsOnlyViewEnabled = True
	oView = oBOM.BOMViews(3)
	For Each oRow As BOMRow In oView.BOMRows
		If oRow.ComponentDefinitions(1) Is oOcc.Definition
			pRow = oRow
			Exit For
		End If
	Next
	'-------------------------------------------------------
End If
Dim oNum As String = InputBox("Set item number of " & oOcc.Name, "Item number", pRow.ItemNumber)
'If itemnumber already exists, switch the numbers of the parts
For Each oRow As BOMRow In oView.BOMRows
	If oRow.ItemNumber = oNum Then oRow.ItemNumber = pRow.ItemNumber
Next
'--------------------------------------------------------------
pRow.ItemNumber = oNum
0 Likes
Message 3 of 9

manu.marjanen
Advocate
Advocate

Something like this.

For example, If parameter("something") is True  Then Part:1 part number is 10.

0 Likes
Message 4 of 9

JhoelForshav
Mentor
Mentor

Is the parameter in the assembly or in the part? Do you want to change the itemnumber in structured or parts only BOM view? What are the conditions and parameter name? Like, if a certain condition is met, the item number should be 10, but what should it be if that condition isn't met?

0 Likes
Message 5 of 9

JhoelForshav
Mentor
Mentor
Accepted solution

Here's an example if the parameter is in the assembly and its called "itemNum"

It'll change the item number of the occurrence in the assembly called "Part1:1" in structured BOM view if the parameter is True.

 

Dim oAsm As AssemblyDocument = ThisDoc.Document
Dim oOcc As ComponentOccurrence = oAsm.ComponentDefinition.Occurrences.ItemByName("Part1:1")
Dim oBOM As BOM = oAsm.ComponentDefinition.BOM
oBOM.StructuredViewEnabled = True
Dim oView As BOMView = oBOM.BOMViews.Item(2)
Dim pRow As BOMRow
For Each oRow As BOMRow In oView.BOMRows
	If oRow.ComponentDefinitions(1) Is oOcc.Definition
		pRow = oRow
		Exit For
	End If
Next
If itemNum Then pRow.ItemNumber = 10

 

0 Likes
Message 6 of 9

manu.marjanen
Advocate
Advocate

This is really good. Thanks a lot

0 Likes
Message 7 of 9

manu.marjanen
Advocate
Advocate

I need more help.

If "itemNum" true then "part:1"  item number is what i want. But when "itemNum" is false then "part:1" is not in assembly and thins code give me an error.

 

Focusing, "itemNum" True "part:1" is in assembly and  "itemNum" False "part:1" is not in assembly.

0 Likes
Message 8 of 9

JhoelForshav
Mentor
Mentor

Hi @manu.marjanen 

How about this then 🙂

If itemNum
Dim oAsm As AssemblyDocument = ThisDoc.Document
Dim oOcc As ComponentOccurrence = oAsm.ComponentDefinition.Occurrences.ItemByName("Part1:1")
Dim oBOM As BOM = oAsm.ComponentDefinition.BOM
oBOM.StructuredViewEnabled = True
Dim oView As BOMView = oBOM.BOMViews.Item(2)
Dim pRow As BOMRow
For Each oRow As BOMRow In oView.BOMRows
	If oRow.ComponentDefinitions(1) Is oOcc.Definition
		pRow = oRow
		Exit For
	End If
Next
pRow.ItemNumber = 10
End If
0 Likes
Message 9 of 9

manu.marjanen
Advocate
Advocate

Now work the way i want, thank you 😃

0 Likes