vb.netsolidworks

SolidWorks API Delete Revision Table


The issue I am having is using the API I can get a macro to sometimes delete the table. On some drawings method A works, on some method B, and others nothing works. I suspect it may have something to do with one source template being created in France, but I am not sure. I also have a suspicion that the location of the table may be a factor.

I am NOT a programmer, I am usually able to combine information from here, some faint recollection of VB back in college, and recording some items, then making it work. Usually I am successful, but this one has me stumped. Method A:

'Captures the item name of the table
    sName = swTable.GetAnnotation.GetName & "@Sheet1"
    
'Deletes the table
Set Part = swApp.ActiveDoc
boolstatus = Part.Extension.SelectByID2(sName, "REVISIONTABLE", 0, 0, 0, False, 0, Nothing, 0)
Part.EditDelete

I have also added the vSheetNames (from method B) to the above to accommodate the sheet name changing, or being in French Method B (found on web):

vSheetNames = swDraw.GetSheetNames
For i = 0 To UBound(vSheetNames)
    swDraw.ActivateSheet vSheetNames(i)
'    Debug.Print vSheetNames(i)
    Set swSheet = swDraw.GetCurrentSheet
    Set RevTableAnn = swSheet.RevisionTable
    
    If Not RevTableAnn Is Nothing Then
'        Debug.Print "Revision Table is SOMETHING! Double check for revTableFeat now!"
        Set revTableFeat = RevTableAnn.RevisionTableFeature
        If revTableFeat Is Nothing Then
'            Debug.Print "Revision table feature is nothing but a revision table exists!"
            Set swTableAnn = RevTableAnn
            Set swAnn = swTableAnn.GetAnnotation
        
            boolstatus = swAnn.Select3(False, swSelData)
            bRet = swModelDocExt.DeleteSelection2(swDeleteSelectionOptions_e.swDelete_Absorbed)
            Debug.Print "Revision table annotation deleted? " & bRet
        

        Else
'            Debug.Print "Revision table feature is present! Delete it!"
            Set swFeat = RevTableAnn.RevisionTableFeature.GetFeature
            bRet = swFeat.Select2(False, 0)
            bRet = swModelDocExt.DeleteSelection2(swDeleteSelectionOptions_e.swDelete_Absorbed)
        End If
    Else
'        Debug.Print "Revision Table is nothing! Sheet can be skipped!"
    End If
    

Next

Method A worked for all of our original sheet formats, but has never worked on the French versions. Method B works on some, and others it does not. I am at a loss. Happy to share more information and items to test with. Would appreciate any help! Thank you.**

I have tried multiple methods (shown above) as well as recording myself and comparing the data - it looks the same?


Solution

  • This is the method that I typically use. It selects the annotation directly without the need to deal with features/sub-features on the feature tree. I believe working with the features requires that each sheet be activated prior to getting and selecting the revision table which takes a good bit more time than this.

    It's possible that the use of swModelDocExt.DeleteSelection2 could be causing your issue as well.

    Sub main()
        Dim swApp As SldWorks.SldWorks
        Dim swModel As ModelDoc2
        Dim swSheet As Sheet
        Dim swRevTable As RevisionTableAnnotation
        Dim swTable_Rev As TableAnnotation
        Dim swAnno As Annotation
        
        Set swApp = Application.SldWorks
        Set swModel = swApp.ActiveDoc
        
        Set swCurFeature = swModel.FirstFeature
        
        While Not swCurFeature Is Nothing
            If swCurFeature.GetTypeName2 = "DrSheet" Then
                Set swSheet = swCurFeature.GetSpecificFeature2
                Set swRevTable = swSheet.RevisionTable
                
                If Not swRevTable Is Nothing Then
                    Set swTable_Rev = swRevTable
                    
                    Set swAnno = swTable_Rev.GetAnnotation
                    swAnno.Select3 False, Nothing
                    swModel.EditDelete
                End If
            End If
                
            Set swCurFeature = swCurFeature.GetNextFeature
        Wend
    
    End Sub