5 Replies Latest reply on Aug 18, 2014 9:09 AM by Adam Hoffman

    Deleting last row of BOM using API

    Suraj Khosla

      I have a BOM and want to delete the last row (row number 3) using the SW API, I have tried to record a macro to do this and got the following:


      boolstatus = Part.Extension.SelectByID2("DetailItem12@1", "ANNOTATIONTABLES", -7.31662186382903E-04, 0.184270796061969, 0, False, 0, Nothing, 0)



      It selects and deletes the entire BOM and not the row which was selected during recording.

        • Re: Deleting last row of BOM using API
          Adam Hoffman

          Is this in a drawing or in an assembly document?

            • Re: Deleting last row of BOM using API
              Suraj Khosla

              The BOM is on a drawing.

                • Re: Deleting last row of BOM using API
                  Adam Hoffman

                  Start a new macro and paste this code into coding window. Make sure to replace all existing code in the window with this code.


                  '                          Delete Last Row In BOM Macro                  '
                  '                                By Adam Hoffman                                 '

                  Dim swApp                  As SldWorks.SldWorks
                  Dim swModel               As SldWorks.ModelDoc2
                  Dim swFeat                 As SldWorks.Feature
                  Dim swBOMFeat         As SldWorks.BomFeature
                  Dim vTableArr             As Variant
                  Dim vTable                 As Variant
                  Dim swTable              As SldWorks.TableAnnotation
                  Dim iRow                  As Integer
                  Dim bDelete               As Boolean


                  Sub main()


                  Set swApp = Application.SldWorks
                  Set swModel = swApp.ActiveDoc


                  If swModel Is Nothing Or swModel.GetType <> swDocDRAWING Then
                     MsgBox ("You Must Run This Macro Inside A Drawing")

                     Exit Sub
                  End If


                  Set swFeat = swModel.FirstFeature


                  Do While Not swFeat Is Nothing
                     If swFeat.GetTypeName = "BomFeat" Then


                        Set swBOMFeat = swFeat.GetSpecificFeature2
                        Exit Do
                        Set swFeat = swFeat.GetNextFeature
                     End If


                  If Not swBOMFeat Is Nothing Then


                     vTableArr = swBOMFeat.GetTableAnnotations


                     For Each vTable In vTableArr
                         Set swTable = vTable
                         If Not swTable Is Nothing Then

                           iRow = swTable.TotalRowCount
                           If iRow > 1 Then
                              bDelete = swTable.DeleteRow(iRow - 1)
                           End If
                        End If
                     Next vTable
                  End If

                  End Sub