Purging / Deleting instances of Sketched Symbols

Purging / Deleting instances of Sketched Symbols

GeorgK
Advisor Advisor
746 Views
4 Replies
Message 1 of 5

Purging / Deleting instances of Sketched Symbols

GeorgK
Advisor
Advisor

Hello together,

 

I found this piece of code to delete instances of sketched symbols.

 

https://forums.autodesk.com/t5/inventor-customization/vba-purging-deleting-isntances-of-sketched-sym...

 

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

When I run the code not all sketched symbols are deleted. I have to run the code several times. Is there any solution to run the code only once to delete the sketched symbols?

 

Thanks

Georg

0 Likes
Accepted solutions (1)
747 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable

Hi Georg,

 

In your piece of code it will delete the sketched symbol if its name is set to REVISION BLOCK else it will not delete. my modified code might be helpful for you.

 

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


Dim oSheet As Sheet

For Each oSheet In oDoc.Sheets

     Dim oSketchedSymbolDef As SketchedSymbolDefinition
    For each oSketchedSymbolDef in oDoc.SketchedSymbolDefinitions
        oSketchedSymbolDef.delete 'It will delete all the sketched symbols
   next

Next
End Sub
0 Likes
Message 3 of 5

GeorgK
Advisor
Advisor

Hello Srinivas,

 

I would like to delete only the "REVISION BLOCK". But in my case I have several "REVISION BLOCK" in my drawing. The problem is that I have to use the program several times to delete all the "REVISION BLOCK".

 

Do you have the same error?

 

Thanks

 

Georg

0 Likes
Message 4 of 5

Anonymous
Not applicable
Accepted solution

Try this code

 

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


Dim oSheet As Sheet

For Each oSheet In oDoc.Sheets

     Dim oSketchedSymbolDef As SketchedSymbol
    For each oSketchedSymbolDef in oSheet.SketchedSymbols
if osketchedSymbolDef.Name = "REVISION BLOCK" then oSketchedSymbolDef.delete 'It will delete all the sketched symbols
endif next Next End Sub
Message 5 of 5

GeorgK
Advisor
Advisor

Hello Srinivas,

 

thank you very much. It's working now.

 

Georg

 

 

0 Likes