Hi @J.Classens. If @JhoelForshav 's solution isn't what you were looking for then maybe something like this would work for you. Basically, when you run it the first time, it creates a custom iProperty called "BOMLocked", with the value set to True (Boolean). Then when you try to run it again, it checks for that custom iProperty, and if found, if it is True, it will then exit the rule, without going any further. Therefore it will only sort and renumber the BOM that first time.
Sub Main()
Dim oAsmDoc As AssemblyDocument = ThisDoc.Document
Dim oLocked As Boolean = False
Try
oLocked = oAsmDoc.PropertySets(4).Item("BOMLocked").Value
Catch
End Try
If oLocked Then Exit Sub
Dim oAsmCompDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition
Dim oBOMView As BOMView = oAsmCompDef.BOM.BOMViews.Item("Structured")
oBOMView.Sort("Vendor", 1, "Part Number", 1)
oBOMView.Renumber(001)
Try
oAsmDoc.PropertySets(4).Item("BOMLocked").Value = True
Catch
oAsmDoc.PropertySets(4).Add(True, "BOMLocked")
End Try
End Sub
You could also use a question there to inform the user that it has already been sorted/renumbered before, are you sure you want to sort/renumber again? If No, exit the rule, if Yes, continue.
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.
If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡or you can Explore My CONTRIBUTIONS
Wesley Crihfield

(Not an Autodesk Employee)