AnsweredAssumed Answered

How to insert a TOP LEVEL ONLY BOM table

Question asked by Dennis Chan on Feb 1, 2018
Latest reply on Jan 20, 2019 by Dennis Chan

hi everyone~

I have a macro which can insert a top-level only BOM table into an assembly, and save as an excel file.

 

That works fine when swBomType is "PartsOnly" or "Indented".

 

But if swBomType is TopLevelOnly,it fail...

Can anybody help?

many thanks

 

 

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swBOMTable As SldWorks.BomTableAnnotation
Dim swTable As SldWorks.TableAnnotation
Dim swAnn As SldWorks.Annotation
Const BOMTemplate As String = ""
Dim ConfigName As String
Sub main()
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    
    ConfigName = swModel.GetActiveConfiguration.Name
    Set swBOMTable = swModel.Extension.InsertBomTable(BOMTemplate, 0, 0, swBomType_e.swBomType_TopLevelOnly, ConfigName)
    Set swTable = swBOMTable
    ModelPath = swModel.GetPathName
    ModelPathName = Left(ModelPath, InStrRev(ModelPath, "\"))
    FileName = Left(swModel.GetTitle, Len(swModel.GetTitle) - 7)
    swTable.SaveAsText ModelPathName & FileName & ".xls", vbTab
    Set swAnn = swTable.GetAnnotation
    swAnn.Select3 False, Nothing
    swModel.EditDelete
End Sub

Outcomes