VBA - Purging/Deleting isntances of Sketched Symbols

VBA - Purging/Deleting isntances of Sketched Symbols

thomas.anderson188
Explorer Explorer
821 Views
2 Replies
Message 1 of 3

VBA - Purging/Deleting isntances of Sketched Symbols

thomas.anderson188
Explorer
Explorer

Good morning all!  I have been writing a few programs to help me speed up some of the nittygritty work that we all have to do from time to time.  Currently there is a need to go through a very large quantity of drawings that have revision blocks and revision tags in them.  For ease, they are just blocks that are inserted as Sketched Symbols.  These symbols are built into our standard template file, so they will always be available for use, but I want to purge them off of the actual document so they aren't used anywhere.  Currently I have the following code but I get a "Method 'Delete' of object 'SketchedSymbolDefinition' failed"

 

I've bounced around the code quite a bit, and I don't know the solution. 

 

Thanks for all the help!

 

----------------------------------------------------------------------

 

Public Revision As Integer

Private Sub Validateform3()

    If Revision_Check = 0 Then
        Revision = 0
    Else
        Revision = 1
    End If
    


End Sub

Private Sub CommandButton1_Click()
    Unload Me
End Sub

Private Sub Revision_Check_Click()
    Call Validateform3
End Sub

Private Sub Run_Cleanup_Click()
   Call Validateform3
    
    Dim oDoc As DrawingDocument
    Set oDoc = ThisApplication.ActiveDocument
    
Dim oSketchedSymbolDef As SketchedSymbolDefinition

    If Revision = 1 Then
        For Each oSketchedSymbolDef In oDoc.SketchedSymbolDefinitions
                If oSketchedSymbolDef.Name = "REVISION BLOCK" Then
                oSketchedSymbolDef.Delete
            
                
                Else
                End If
        Next
    End If

End Sub

Accepted solutions (1)
822 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
Accepted solution

Thomas,

I found that first if must be deleted from the sheet before it could be removed from the library. See code below.

 

 Public Sub Sketchsymbol_Delete()
   
Dim oDoc As DrawingDocument
Set oDoc = ThisApplication.ActiveDocument

 

Dim oSheet As Sheet

 

For Each oSheet In oDoc.Sheets

    oSheet.Activate

    Dim oSketchedSymbolDef As SketchedSymbolDefinition
    Set oSketchedSymbolDef = oDoc.SketchedSymbolDefinitions.Item("REVISION BLOCK")
   
   
    Set oSheet = oDoc.ActiveSheet

 

    Dim oTG As TransientGeometry
    Set oTG = ThisApplication.TransientGeometry

    Dim oSketchedSymbol As SketchedSymbol


   
        For X = 1 To oSheet.SketchedSymbols.Count
            If oSheet.SketchedSymbols.Item(X).Name = "REVISION BLOCK" Then
            oSheet.SketchedSymbols.Item(X).Delete 'Delete it from each sheet
            End If
        Next

 

Next

 

oSketchedSymbolDef.Delete 'Delete it from the library


End Sub

 

Let me know if this works for you.

Please Kudo if this solution works for you.

Wayne

Message 3 of 3

thomas.anderson188
Explorer
Explorer

Thank you very much! That was exactly the problem and she is up and running now!

0 Likes