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