5 Replies Latest reply on Jul 13, 2018 2:40 AM by Marcus Bärlin

    Get Excel BOM properties

    Marcus Bärlin



      I'm looking for the api to get the excel bom properties like "show parts only", "show top level subassemblies and part only" or "show assemblies and parts in an indented list"?


      Thanks a lot


        • Re: Get Excel BOM properties
          Artem Taturevych

          You can control this via user preferences. Check the Remarks section here: 2017 SOLIDWORKS API Help - InsertBomTable Method (IView)

          • Re: Get Excel BOM properties
            Gang S.

            Hi, Marcus

                 here I got an example from the API user preferences.the following 3 photos figured out the result. I don't know if this is what you want.


            show assemblies and parts in an indented list.pngshow parts only.pngshow top level subassemblies and part only.png

            • Re: Get Excel BOM properties
              Gang S.

              i paste the vba scripts for you here!


              Sub TraverseComponent(swComp As SldWorks.Component2, nLevel As Long)

                  Dim vChildComp As Variant

                  Dim swChildComp As SldWorks.Component2

                  Dim swCompConfig As SldWorks.Configuration

                  Dim sPadStr As String

                  Dim i As Long

                  For i = 0 To nLevel - 1

                      sPadStr = sPadStr + "  "

                  Next i

                  vChildComp = swComp.GetChildren

                  For i = 0 To UBound(vChildComp)

                      Set swChildComp = vChildComp(i)

                      TraverseComponent swChildComp, nLevel + 1


                      If LCase(Right(swChildComp.GetPathName, 6)) = "sldprt" Then   'Dont export assembly nodes

                          Debug.Print sPadStr & swChildComp.Name2

                      End If


                  Next i

              End Sub


              Sub main()

                  Dim swApp As SldWorks.SldWorks

                  Dim swModel As SldWorks.modelDoc2

                  Dim swAssy As SldWorks.assemblyDoc

                  Dim swConf As SldWorks.Configuration

                  Dim swRootComp As SldWorks.Component2

                  Dim bRet As Boolean

                  Dim fileName As String

                  Dim errors As Long

                  Dim warnings As Long

                  Set swApp = CreateObject("SldWorks.Application")


                  Set swModel = swApp.ActiveDoc

                  Set swConf = swModel.GetActiveConfiguration

                  Set swRootComp = swConf.GetRootComponent3(True)


                  TraverseComponent swRootComp, 1

              End Sub