ds-blue-logo
Preview  |  SOLIDWORKS USER FORUM
Use your SOLIDWORKS ID or 3DEXPERIENCE ID to log in.
DCDennis Chan01/02/2018

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