Ilogic >> Delete Sketched Symbol

Ilogic >> Delete Sketched Symbol

joris.engelbertink
Enthusiast Enthusiast
3,117 Views
7 Replies
Message 1 of 8

Ilogic >> Delete Sketched Symbol

joris.engelbertink
Enthusiast
Enthusiast

Hello,

 

Can someone help me out with some iLogic to delete a sketched symbol from a drawing by its name? 

I'm quite a beginner with this, so I might be overlooking something..

 

This is the code is have: 

 

Dim oDrawDoc As DrawingDocument= ThisApplication.ActiveDocument
Dim oSketchedSymbolDef As SketchedSymbolDefinition

If oDrawDoc.oSketchedSymbolDef.Item = "Sketched Symbol Name" Then
oSketchedSymbolDef.Delete

Else
End If

 

Thanks!

 

0 Likes
Accepted solutions (1)
3,118 Views
7 Replies
Replies (7)
Message 2 of 8

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @joris.engelbertink,


Something like this should work to delete a symbol from the sheet. If you are wanting to delete the symbol from the drawing, you will need to go through each sheet and delete any instance of the symbol, and delete the symbol definition. If that is what you are after, post back and someone can likely provide an example.

 

'Define the drawing document
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisDoc.Document

'Iterate through each symbol in the active sheet
For Each oSymbol In oDrawDoc.ActiveSheet.SketchedSymbols
	'look for the symbol by name
	If oSymbol.Name = "Sketched Symbol Name" Then
		oSymbol.Delete
	End If
Next 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

EESignature

Message 3 of 8

Anonymous
Not applicable

Nice, Curtis! I was always under the impression the delete method wouldn't work if the symbol def was referenced. I learned something new. Can I go home now? 🙂 

0 Likes
Message 4 of 8

Anonymous
Not applicable

I guess it's all the difference between an instance and the actual object definition.

0 Likes
Message 5 of 8

SPALANIAPPANTN47S
Enthusiast
Enthusiast

In case, if the drawing contains multiple sheets , how to modify the program ? 

0 Likes
Message 6 of 8

Mike_Y2
Advocate
Advocate

This loops through all sheets in the active drawing document. Note replace the name "test" to the name of your sketch symbol...

 

'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

'Define the drawing document
Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument

'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 = "test" Then
			oSymbol.Delete
		End If
	Next
Next
0 Likes
Message 7 of 8

Mike_Y2
Advocate
Advocate

@SPALANIAPPANTN47S  see above

0 Likes
Message 8 of 8

Luke.NashWU9MY
Participant
Participant

Is there a way to modify this to go through and change all sheets and all open drawings?

0 Likes