Deleting/Replacing Sketch Symbols on multiple sheets in IDW

Deleting/Replacing Sketch Symbols on multiple sheets in IDW

eugene.morales
Enthusiast Enthusiast
920 Views
2 Replies
Message 1 of 3

Deleting/Replacing Sketch Symbols on multiple sheets in IDW

eugene.morales
Enthusiast
Enthusiast

Hi All,

 

I've been looking for codes that can delete and replace a specific inserted sketch symbol in a drawing sheet or multiple sheet but I can only find something that I can insert a symbol. We use multiple sheets in an IDW and used the sketched symbols in every sheet. If there's a code that can do this task, it can reduce our work in a way and to be efficient. I'm not that savvy in coding and still learning slowly in this field. It will be much appreciated if someone can help me out.

0 Likes
921 Views
2 Replies
Replies (2)
Message 2 of 3

A.Acheson
Mentor
Mentor

Can you post the code you are using for the insert of the symbol. Is the symbol held in the symbol library or a template sheet? The symbols library would be the best place to fetch this from. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 3

eugene.morales
Enthusiast
Enthusiast

@A.Acheson 

 

Hi, Thank you for your response to my inquiry but I've managed to find a code that would suit what we need. The code below lets me add them in all of my sheets and I've got the code to delete them also or I can specifically add symbols into my sheet using a form. The form contains buttons of every rule I've got to derive the series of symbols I need.

'----------------START OF iLOGIC CODE-----------------------------------

Sub main	
    ' Set a reference to the drawing document.
    ' This assumes a drawing document is active.
    Dim oDrawDoc As DrawingDocument
    oDrawDoc = ThisApplication.ActiveDocument
    Dim oSheet As Sheet
    oSheet = oDrawDoc.ActiveSheet
	
	    ' Obtain a reference to the desired sketched symbol definition.
    Dim oSketchedSymbolDef As SketchedSymbolDefinition
    oSketchedSymbolDef = oDrawDoc.SketchedSymbolDefinitions.Item("IFA Stamp")
	
	'Check this is a drawing document...
If Not TypeOf ThisDoc.Document Is DrawingDocument Then
	MessageBox.Show("This rule will only run on a drawing", _
	"Realm", MessageBoxButtons.OK, MessageBoxIcon.Information)
	'Exit sub if not a drawing document
	Exit Sub
End If

'Loop through sheets
For Each oSheet In oDrawDoc.Sheets 
	'Loop through each symbol
	'For Each oSymbol In oSheet.SketchedSymbols
		'look for the symbol by name



   Dim oTG As TransientGeometry
    oTG = ThisApplication.TransientGeometry

    ' Add an instance of the sketched symbol definition to the sheet.
    ' Rotate the instance by 45 degrees and scale by .75 when adding.
    ' The symbol will be inserted at (0,0) on the sheet. Since the
    ' start point of the line was marked as the insertion point, the
    ' start point should end up at (0,0).
    Dim oSketchedSymbol As SketchedSymbol
    oSketchedSymbol = oSheet.SketchedSymbols.Add(oSketchedSymbolDef, oTG.CreatePoint2d(9, 54.5), 0, 1, sPromptStrings)

Next	
End Sub

'--------------------END OF iLOGIC CODE-----------------------------------

 

The code below can delete the symbol in all of the sheet.

'----------------START OF iLOGIC CODE-----------------------------------

Sub main	
    ' Set a reference to the drawing document.
    ' This assumes a drawing document is active.
    Dim oDrawDoc As DrawingDocument
    oDrawDoc = ThisApplication.ActiveDocument
    Dim oSheet As Sheet
    oSheet = oDrawDoc.ActiveSheet
	
	'Check this is a drawing document...
If Not TypeOf ThisDoc.Document Is DrawingDocument Then
	MessageBox.Show("This rule will only run on a drawing", _
	"Realm", MessageBoxButtons.OK, MessageBoxIcon.Information)
	'Exit sub if not a drawing document
	Exit Sub
End If

'Loop through sheets
For Each oSheet In oDrawDoc.Sheets 
	'Loop through each symbol
	For Each oSymbol In oSheet.SketchedSymbols
		'look for the symbol by name
		If oSymbol.Name = "IFA Stamp" Then
			oSymbol.Delete
		End If
	
	Next	
Next	
End Sub

'--------------------END OF iLOGIC CODE----------------------------------

 

And this one will add the symbol to the current sheet.

'----------------START OF iLOGIC CODE-----------------------------------

'Sub Main() 
' Set a reference to the drawing document.
' 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("IFA Stamp")
 
Dim oSheet As Sheet = oDrawDoc.ActiveSheet
 
'create insertion point, coordinates - in cm !
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oInsertionPoint As Point2d = oTG.CreatePoint2d(9, 54.5)
 
' Add an instance of the sketched symbol definition to the sheet.
' Rotate angle = 0 radians,
' scale = 1 when adding
' no prompt text
Dim oSketchedSymbol As SketchedSymbol _
       = oSheet.SketchedSymbols.Add( _
             oSketchedSymbolDef, _
             oInsertionPoint, _
             0, 1, Nothing)
'End Sub

'--------------------END OF iLOGIC CODE-----------------------------------

 

Screenshot of my form below 😄

eugenemorales_0-1631052912458.png

 

The following codes let me customize their orientation in the drawings sheets so it's automated and I don't need to reorient it's position whenever I insert a symbol.

 

I would like to share it and hopefully it can be helpful to others too.