By Adam Nagy
In case of the UI of AutoCAD Mechanical there are three keys you can set for the sort:
Sorting based on keys is a UI only method. In the API you don't really need that since there you have full control over how the items should be sorted. You can come up with any sorting logic, it just needs to set the SortPriority property of each McadBOMItem before calling applySort().
The following VBA sample sorts based on the Item Number property of the BOM items:
Public Sub SortBom() Dim symMgr As McadSymbolBBMgr Set symMgr = ThisDrawing.Application. _ GetInterfaceObject("SymBBAuto.McadSymbolBBMgr") Dim BOMs As McadBOMs Set BOMs = symMgr.bommgr.GetAllBOMTables(False) Dim BOM As McadBOM Set BOM = BOMs.item(0) Dim item As McadBOMItem For Each item In BOM.Items Dim p As Long: p = Val(item.ItemNumber) If p > 0 Then item.SortPriority = p Next BOM.applySort End Sub
Note: the lower the SortPriority value the earlier (more top in the table) the item will appear in the list. Also its value does not have to be unique.