Friday 25 May 2012

iLogic to sort the BOM

I have been struggling for about a week now to write some iLogic code to Sort and Re-Number the BOM in the assembly mode. I managed to find a lot of information for the Parts List, but allas, they are two different things.

Anyway, I request help on the forums which proved futile, so I had to make something myself, which I guess is good, as I learnt how to use the VB help and apply the same rules to iLogic.

The piece of code works to around 99%, I have had to cheat it a bit, as I can't get the sort to work every time?

' Set a reference to the assembly document.
' This assumes an assembly document is active.
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument
Dim oBOM As BOM
oBOM = oDoc.ComponentDefinition.BOM
Dim oBOMView As BOMView
oBOMView = oBOM.BOMViews.Item("Parts Only")
' Sort the BOM
Call oBOMView.Sort("BOM Structure",True)
' Sort the BOM with a custom field
Call oBOMView.Sort("TYPE",True)
'Call oBOMView.Sort("Part Number",True)
'This is the line that I want to use, but is inconsistent.
Call oBOMView.Sort("BOM Structure",True ,"TYPE",True ,"Part Number",True)
'Re-Number the BOM
Call oBOMView.Renumber(1, 1)