Remove symbol from all open drawings

Remove symbol from all open drawings

Anonymous
Not applicable
487 Views
2 Replies
Message 1 of 3

Remove symbol from all open drawings

Anonymous
Not applicable

Hi,

 

So I am trying to make a code where if there is multiple drawings open, the code will start with the left 'tab' drawing, locate a specific symbol, remove it, move to the next drawing, remove it and so on until all symbols have been removed. The pages dont even have to shift, as long as it batch removes that specific symbol from all open drawings on Inventor, I am happy. I am really new to coding so sorry if it doesnt make sense or is really easy to do.

 

This is what I have written so far:

For Each doc As Document In ThisApplication.Documents.VisibleDocuments
For Each oSymbol In oDrawDoc.VisibleDocuments.SketchedSymbols
	'look for the symbol by name
	If oSymbol.Name = "WARNING" Then
		oSymbol.Delete
	End If
Next
0 Likes
Accepted solutions (1)
488 Views
2 Replies
Replies (2)
Message 2 of 3

A.Acheson
Mentor
Mentor
Accepted solution

You will need to look only at the drawing document then in the sheet collection then loop over each sheet and delete the symbol then you can delete the symbol from the document. I have tested the below but as always open a sample drawing and test. 

 

For Each doc As Document In ThisApplication.Documents.VisibleDocuments
	
	'Filter by document type Drawing
	If doc.DocumentType = kDrawingDocumentObject Then
	'MessageBox.Show(doc.FullFileName, "Title")

		Dim oSheets As Sheets
		Dim oSheet As Sheet
		oSheets = doc.Sheets
		
		'Loop through each sheet
		For Each oSheet In oSheets
			
			'Loop through each symbol in the active sheet
			For Each oSymbol In oSheet.SketchedSymbols
				
				'look For the symbol by name
				If oSymbol.Name = "WARNING" Then
					oSymbol.Delete
				End If
			Next 
			
			'Delete symbol in the document after all symbols have been removed from the sheets
			Try
			Dim oSketchedSymbolDef As SketchedSymbolDefinition 
			 oSketchedSymbolDef = doc.SketchedSymbolDefinitions.Item("WARNING")'Symbols
			oSketchedSymbolDef.Delete
			Catch
			End Try


		Next
	End If

Next
 

 

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

Anonymous
Not applicable

That worked perfectly, thanks heaps for the help!

0 Likes