Just an important addition:
Add a line to sort BOM to part number before renumbering then all classes will be sorted in class and Part numbers:
Dim oBOM As BOM = ThisAssembly.Document.ComponentDefinition.BOM
Dim oStoreType As Inventor.Property
oBOM.StructuredViewEnabled = True
oBOM.BOMViews("Structured").Sort("Store Type", True)
oBOM.BOMViews("Structured").Renumber(9001, 1)
iMANPART = 0
iSTOREPART = 2000
iFAST = 4000
iMAT = 5000
iMANASS = 6000
iJIG = 7000
iREF = 8000
oBOM.BOMViews("Structured").Sort("Part Number", True)
For Each oBOMRow As BOMRow In oBOM.BOMViews.Item("Structured").BOMRows
Dim oDoc As Document = oBOMRow.ComponentDefinitions(1).Document
Try
oStoreType = oDoc.PropertySets.Item("Inventor User Defined Properties").Item("Store Type")
Catch
Logger.Info("Property not found")
Continue For
End Try
If oStoreType.Value = "MANUFACTURED PART" Then
iMANPART = iMANPART + 1
oBOMRow.ItemNumber = iMANPART
End If
If oStoreType.Value = "STORE PART" Then
iSTOREPART = iSTOREPART + 1
oBOMRow.ItemNumber = iSTOREPART
End If
If oStoreType.Value = "JIG" Then
iJIG = iJIG + 1
oBOMRow.ItemNumber = iJIG
End If
If oStoreType.Value = "REF PART" Then
iREF = iREF + 1
oBOMRow.ItemNumber = iREF
End If
Dim oBDoc As Document = oBOMRow.ComponentDefinitions(1).Document
Try
oPartType = oBDoc.PropertySets.Item("Inventor User Defined Properties").Item("Part Type")
Catch
Logger.Info("Property not found")
Continue For
End Try
If oPartType.Value = "FASTENER" Then
iFAST = iFAST + 1
oBOMRow.ItemNumber = iFAST
End If
If oPartType.Value = "ASSEMBLY" Then
iMANASS = iMANASS + 1
oBOMRow.ItemNumber = iMANASS
End If
If oStoreType.Value = "MATERIAL" Then
iMAT = iMAT + 1
oBOMRow.ItemNumber = iMAT
End If
Next
oBOM.BOMViews("Structured").Sort("Item", True)