AnsweredAssumed Answered

Macro to delete General Table by Name not working

Question asked by Mark Soldan on Dec 16, 2019
Latest reply on Dec 28, 2019 by Elmar Klammer

As part of a larger Macro, I need to scan drawing files for general tables with specific names and delete them.  I've tried several methods from examples found here or from CodeStack, but can't get them to work.  Either nothing happens or I get the message "None of the selected entities could be deleted".  Here's the code that shows several methods I have tried.  Any advice is appreciated.

 

I'm not sure of the best way to paste code, so here's my attempt

 

 

Sub main()

    Dim swApp                       As SldWorks.SldWorks

    Dim swModel                     As SldWorks.ModelDoc2

    Dim BoolStatus                  As Boolean

    Dim swFeat                      As SldWorks.Feature

    Dim swSubFeat                   As SldWorks.Feature

    Dim TARGET_TABLE_NAME           As String

 

    TARGET_TABLE_NAME = "General Table3" ' This is the name of the General Table to delete

    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

    Set swFeat = swModel.FirstFeature

 

    ' Step through the feature tree, looking for a GENERAL TABLE with a name that matches TARGET_TABLE_NAME

    Do Until swFeat Is Nothing

        Set swSubFeat = swFeat.GetFirstSubFeature

         Do Until swSubFeat Is Nothing

            If swSubFeat.GetTypeName = "GeneralTableFeature" Then

                If swSubFeat.Name = TARGET_TABLE_NAME Then

                    Debug.Print "Bingo"

                    BoolStatus = swModel.Extension.SelectByID2(swSubFeat.Name, swSubFeat.GetTypeName, 0, 0, 0, False, 0, Nothing, 0)

                    'Delete attempt #1

                        Call swModel.Extension.SelectByID2(swSubFeat.Name, swSubFeat.GetTypeName, 0, 0, 0, False, 0, Nothing, 0)

                    'Delete attempt #2

                        Call swModel.Extension.SelectByID2(swSubFeat.Name, swSubFeat.GetTypeName, 0, 0, 0, True, 0, Nothing, 0)

                    'Delete attempt #3

                        swModel.EditDelete

                        BoolStatus = swModel.DeleteSelection(False)

                    'Delete attempt #4

                        swModel.Extension.DeleteSelection2 swDeleteSelectionOptions_e.swDelete_Absorbed

                        BoolStatus = swModel.DeleteSelection(False)

                End If

            End If

            Set swSubFeat = swSubFeat.GetNextSubFeature

        Loop

        Set swFeat = swFeat.GetNextFeature

    Loop

End Sub

Outcomes