2 Replies Latest reply on Sep 21, 2018 12:19 PM by Stanislav Shiryaev

    BOM get part from row

    Stanislav Shiryaev

      How can I get component from selected row in a BOM via API ? Or is it possible to get number of selected row?

        • Re: BOM get part from row
          Fifi Riri


          This will get you the component of a selected cell

          it won't work if the whole row is selected though.


          Option Explicit

          Dim swApp As SldWorks.SldWorks

          Sub main()

              Dim swModel As SldWorks.ModelDoc2

              Dim swSelectionMgr As SldWorks.SelectionMgr

              Dim swTableAnnotation As SldWorks.TableAnnotation

              Dim firstRow As Long

              Dim lastRow As Long

              Dim firstColumn As Long

              Dim lastColumn As Long

              Dim idx As Long

              Dim strItemNumber As String

              Dim strPartNumber As String

              Dim vModelPathNames As Variant

              Set swApp = Application.SldWorks

              Set swModel = swApp.ActiveDoc

              Set swSelectionMgr = swModel.SelectionManager

              If swSelectionMgr.GetSelectedObjectCount2(-1) = 1 Then

                  Set swTableAnnotation = swSelectionMgr.GetSelectedObject6(1, -1)

                  swTableAnnotation.GetCellRange firstRow, lastRow, firstColumn, lastColumn

                  If firstRow <> -1 Then

                      For idx = firstRow To lastRow

                          vModelPathNames = swTableAnnotation.GetModelPathNames(idx, strItemNumber, strPartNumber)

                          Debug.Print "Component row  :    " & strItemNumber

                          Debug.Print "Component name :    " & strPartNumber

                          Debug.Print "Component path :    " & vModelPathNames(0)


                  End If

              End If

          End Sub