AnsweredAssumed Answered

Sort BOM VBA Macro issues

Question asked by Cad Admin on Apr 21, 2017
Latest reply on Apr 28, 2017 by Cad Admin

I have a macro, that i thought was correct... I want to sort my top level BOMs by "Part number", "ascending" in order of (1) assemblies then (2)parts...

The normal "Sort" GUI works, must be something i cant see...

 

 

Dim swApp        As SldWorks.SldWorks
Dim swModel      As SldWorks.ModelDoc2
Dim swDraw       As SldWorks.DrawingDoc
Dim swBomTable   As SldWorks.BomTableAnnotation
Dim swBomFeat    As SldWorks.BomFeature
Dim swSortData   As SldWorks.BomTableSortData
Dim swSelMgr     As SldWorks.SelectionMgr
Dim swFeat       As SldWorks.Feature
Dim sortArray(2) As String
Dim vTables      As Variant
Dim boolstatus   As Boolean

 

Sub Sort_BOM_Data()

 

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

Set swDraw = swModel

Set swSelMgr = swModel.SelectionManager

Set swFeat = swModel.FirstFeature

 

Do While Not swFeat Is Nothing

If "BomFeat" = swFeat.GetTypeName Then
    swFeat.Select (False)
    Set swBomFeat = swFeat.GetSpecificFeature2
    vTables = swBomFeat.GetTableAnnotations
    Set swBomTable = vTables(0)
End If
Set swFeat = swFeat.GetNextFeature

Loop

 

Set swSortData = swBomTable.GetBomTableSortData

 

swSortData.ColumnIndex(0) = 3

swSortData.Ascending(0) = True

 

sortArray(0) = swBomTableSortItemGroup_e.swBomTableSortItemGroup_Assemblies

sortArray(1) = swBomTableSortItemGroup_e.swBomTableSortItemGroup_Parts

sortArray(2) = swBomTableSortItemGroup_e.swBomTableSortItemGroup_None

 

swSortData.ItemGroups = sortArray

swSortData.DoNotChangeItemNumber = False

 

boolstatus = swBomTable.Sort(swSortData)

 

swModel.ClearSelection2 (True)

 

End Sub

Outcomes