2 Replies Latest reply on Jan 20, 2019 9:33 AM by Dennis Chan

    How to insert a TOP LEVEL ONLY BOM table

    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
      End Sub