9 Replies Latest reply on Jan 6, 2017 10:33 AM by Cad Admin

    Macro to delete BOM

    Shivbhadrasinh Gohil

      Hello all,

       

      Is there any macro that will delete existing BOM from drawing ?

       

      If there is something please share.....:)

       

      Shiv

        • Re: Macro to delete BOM
          Artem Taturevych

          Hello,

           

          Check this macro:

           

          Sub main()

           

              Dim swApp As SldWorks.SldWorks

              Dim swModel As SldWorks.ModelDoc2

              Dim swFeat As SldWorks.Feature

           

              Set swApp = Application.SldWorks

              Set swModel = swApp.ActiveDoc

              Set swFeat = swModel.FirstFeature

           

           

              While Not swFeat Is Nothing

             

                  If "BomFeat" = swFeat.GetTypeName Then

                      swFeat.Select2 False, -1

                      swModel.Extension.DeleteSelection2 swDeleteSelectionOptions_e.swDelete_Absorbed

                  End If

                 

                  Set swFeat = swFeat.GetNextFeature

             

              Wend

             

          End Sub

            • Re: Macro to delete BOM
              Shivbhadrasinh Gohil

              Thanks Artem Taturevych....:)

               

              It's working fine as i want.

               

              One more problem. I hve bunch of drawings so is there any macro that will action as a batch macro...??

               

              Thnks,

              Shiv

                • Re: Macro to delete BOM
                  Artem Taturevych

                  You can install myIntercad http://intercad.com.au/myintercad/ and you will be able to find the 'Batch Macro Runner' and 'Batch Macro Runner Lite' utilities under the myToolkit  area (type in filter box) (this is similar to AppStore but all dedicated to SolidWorks). Those are utilities which allow to run specified macro for the files within the specified folder.

                   

                  Note. You do not need to have token or subscription or even register to use myToolkit - just install and use. You will be able to find more macros and other utilities in the myToolkit.

                   

                  Here is the demonstration video of Batch Macro Runner and myIntercad.myToolkit: http://youtu.be/hRg2AfTLbqo

                • Re: Macro to delete BOM
                  Niklas Hellman

                  Could this be tailored to HIDE the BOM instead of deleting it?

                  • Re: Macro to delete BOM
                    Cad Admin

                    Artem,

                     

                    Could this be modified to delete revision Table? like maybe using "RevisionTableFeat" instead of "BomFeat"

                      • Re: Macro to delete BOM
                        Deepak Gupta

                        Revision Table is a sub feature of the sheet and not the drawing. So you need to use the sub feature codes.

                         

                        Option Explicit
                            Dim swApp As SldWorks.SldWorks
                            Dim swModel As SldWorks.ModelDoc2
                            Dim swFeat As SldWorks.Feature
                            Dim subfeat As SldWorks.Feature
                        Sub main()
                        
                            Set swApp = Application.SldWorks
                            Set swModel = swApp.ActiveDoc
                            Set swFeat = swModel.FirstFeature
                        
                        While Not swFeat Is Nothing
                                Set subfeat = swFeat.GetFirstSubFeature
                                While Not subfeat Is Nothing
                                If "RevisionTableFeat" = subfeat.GetTypeName Then
                                    subfeat.Select2 False, -1
                                    swModel.Extension.DeleteSelection2 swDeleteSelectionOptions_e.swDelete_Absorbed
                                End If
                                Set subfeat = subfeat.GetNextSubFeature
                                Wend
                        Set swFeat = swFeat.GetNextFeature
                        Wend
                        
                        End Sub
                        
                          • Re: Macro to delete BOM
                            Cad Admin

                            Deepak,

                             

                            I like yours better...(LOL).

                             

                            I had ended up with:

                             

                            Option Explicit

                             

                            Dim swApp               As SldWorks.SldWorks

                            Dim swDoc               As SldWorks.ModelDoc2

                            Dim SwSheet            As SldWorks.DrawingDoc

                            Dim swview               As SldWorks.View

                            Dim SwTableRev        As TableAnnotation

                            Dim swAnn               As SldWorks.Annotation

                             

                            Public currentsheet     As Object

                            Dim mytablerev          As Object

                             

                            Sub Main()

                             

                                Set swApp = Application.SldWorks

                                Set swDoc = swApp.ActiveDoc

                                Set SwSheet = swDoc

                               

                                swDoc.ClearSelection2 (True)

                               

                                'Selection of the first view

                                Set swview = SwSheet.GetFirstView

                               

                                'Loop on all views

                                Do While Not swview Is Nothing

                               

                                'Search for annotations related to the view

                                Set SwTableRev = swview.GetFirstTableAnnotation

                               

                                'Loop to analyze whether it is a revision table

                                Do While Not SwTableRev Is Nothing

                                    If SwTableRev.Type = swTableAnnotation_RevisionBlock Then

                                    Set swAnn = SwTableRev.GetAnnotation

                                    swAnn.Select3 True, Nothing

                                    GoTo destructable

                                End If

                               

                                Set SwTableRev = SwTableRev.GetNext

                                    Loop

                               

                                Set swview = swview.GetNextView

                                    Loop

                               

                            destructable:

                               

                                swDoc.EditDelete

                             

                            'insertion table

                            'Set currentsheet = SwSheet.GetCurrentSheet

                            'Set mytablerev = currentsheet.InsertRevisionTable(True, 0, 0, 3, "D:\serv-sec\Solidworks Custom Paths\BOM Template\BOM-STD-VAULT-REV.sldbomtbt")

                            'Attention change the path to the revision table

                            'If true then the table gets on the anchor if not on coordinate 0,0

                             

                            End Sub