Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

VBA code for replacing sketch symbols on the drawing

Anonymous

VBA code for replacing sketch symbols on the drawing

Anonymous
Not applicable

Hi Guys,

I need help with the code (complete beginner :-)) PLEASE.

I got a code already (attached) from the friend that changes drawing to "for construction": changes rev to 0, fills "issued for construction" in revision table and updates dates etc.

It is possible to add to it a code that:

- replace symbol that is currently on the first page only on the drawing named 'A3 For Approval' to

- symbol named 'A3 For Construction'?

PowelMajewski2379_2-1594765536161.png

 

PowelMajewski2379_1-1594765377813.png

You help would be greatly appreciated.

Thank you very much Paul 

 

 

0 Likes
Reply
Accepted solutions (1)
1,328 Views
6 Replies
Replies (6)

Tony_Yates
Advocate
Advocate

Hi Paul,

 

Try this:

'Dim oDoc As DrawingDocument
Dim 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 = "A3 For Approval" Then
        oSketchedSymbolDef.Delete 'It will delete all the sketched symbols
     End If
   Next

Next

' This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument = ThisDrawing.Document


' Obtain a reference to the desired sketched symbol definition.
Dim oSketchedSymbolDef As SketchedSymbolDefinition _
       = oDrawDoc.SketchedSymbolDefinitions.Item("A3 For Construction")

Dim oSheet As Sheet = oDrawDoc.ActiveSheet

'create insertion point, coordinates - in cm !
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oInsertionPoint As Point2d = oTG.CreatePoint2d(40.195195, 10.5)


Dim oSketchedSymbol As SketchedSymbol _
       = oSheet.SketchedSymbols.Add( _
             oSketchedSymbolDef, _
             oInsertionPoint, _
             0, 1, Nothing)

 

change the insertion point number to position where you like it.

Also noticed your stamp name is spelt incorrect. "A3 For Constrcuction" so correct that first.

 

0 Likes

Anonymous
Not applicable

Thank you Tony,

I did try and getting this:

PowelMajewski2379_0-1594768744631.png

 

0 Likes

Tony_Yates
Advocate
Advocate

Hi Paul,

Sorry I just added two rules together.

Try This:

Dim 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 = "A3 For Approval" Then
        oSketchedSymbolDef.Delete 'It will delete all the sketched symbols
     End If
   Next

Next



' Obtain a reference to the desired sketched symbol definition.
Dim oSketchedSymbolDef1 As SketchedSymbolDefinition _
       = oDoc.SketchedSymbolDefinitions.Item("A3 For Construction")



'create insertion point, coordinates - in cm !
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oInsertionPoint As Point2d = oTG.CreatePoint2d(40.195195, 10.5)


Dim oSketchedSymbol As SketchedSymbol _
       = oSheet.SketchedSymbols.Add( _
             oSketchedSymbolDef1, _
             oInsertionPoint, _
             0, 1, Nothing)


0 Likes

Anonymous
Not applicable

Hi Tony,

Thank you, We are almost there :-), it deletes 'for approval' at the first page BUT places 'for construction' at the last page only. It works perfectly when IDW has only one sheet.

PowelMajewski2379_0-1594772191413.png

 

0 Likes

Tony_Yates
Advocate
Advocate
Accepted solution

Hi Paul,

 

changed to active sheet

 

Dim 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 = "A3 For Approval" Then
        oSketchedSymbolDef.Delete 'It will delete all the sketched symbols
     End If
   Next

Next



' Obtain a reference to the desired sketched symbol definition.
Dim oSketchedSymbolDef1 As SketchedSymbolDefinition _
       = oDoc.SketchedSymbolDefinitions.Item("A3 For Construction")



'create insertion point, coordinates - in cm !
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oInsertionPoint As Point2d = oTG.CreatePoint2d(40.195195, 10.5)


Dim oSketchedSymbol As SketchedSymbol _
       = oDoc.ActiveSheet.SketchedSymbols.Add( _
             oSketchedSymbolDef1, _
             oInsertionPoint, _
             0, 1, Nothing)
0 Likes

Anonymous
Not applicable

Thank you VERY MUCH for help Tony, it works perfectly, It will save me hips of time, have a nice day :slightly_smiling_face:

0 Likes