ILogic to Insert External Symbols Into Sketch Symbols Folder

ILogic to Insert External Symbols Into Sketch Symbols Folder

wtriplett
Contributor Contributor
1,598 Views
5 Replies
Message 1 of 6

ILogic to Insert External Symbols Into Sketch Symbols Folder

wtriplett
Contributor
Contributor

Hello,

I am a first time poster and need some ILogic help.  I have been able to use the forum to find code to most of my questions and answers except this one.  Hopefully my explanation is clear.

 

My sketch symbols are located externally.

 

I use a form to select a project number from a list to insert a corresponding sketch into my drawing Sketch Symbols for insertion into my drawing.  This process works fine.

 

I need code place the symbol into Drawing Resources > Sketch Symbols > Subfolder A instead.

 

I also need code to delete the symbols in "Subfolder A" if my project number changes to a new number.

 

I would be very appreciative of any help you can provide. 

 

Thank you!

0 Likes
1,599 Views
5 Replies
Replies (5)
Message 2 of 6

A.Acheson
Mentor
Mentor

Here is a head start with a  vb.net code that works by creating a sub folder in the drawing resource then adds existing symbols to this folder. You will need to adapt as needed to work with your project number and build in error checking etc. 

Search criteria in the API Help- BrowserPane.GetBrowserNodeFromObject Method

https://forums.autodesk.com/t5/inventor-customization/copy-sketched-symbols-with-folders/td-p/713142...

 

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

wtriplett
Contributor
Contributor

Thanks for the information @A.Acheson .  I have seen that post before and could not understand how to use it in my situation.

 

I am having trouble on lines 38 and 39 of this code.  I don't know how to get the symbol into the TB LOGO folder.  As you can see below the project is 0000-1.

  

wtriplett_0-1616337219627.png

I am also trying to figure out how to delete the contents of the "TB Logo" folder when the project changes to a new number.

 

Here is my code and thank you for the help!

 

'this is the name of the symbol library file,
'the path to this location is specified under 
'Tools tab > Application Options button > Files tab 
oSymbolDrawingName = "Title Block Sketch Symbols"

'check file type 
If ThisDoc.Document.DocumentType <> kDrawingDocumentObject Then
Return
End If

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

Dim oSketchSymLib As SketchedSymbolDefinitionLibrary
oSketchSymLib = oDrawDoc.SketchedSymbolDefinitions.SketchedSymbolDefinitionLibraries.Item(oSymbolDrawingName)

Dim oSymbolList As New ArrayList

For Each oSymbolDef In oSketchSymLib.SketchedSymbolDefinitions
	oSymbolList.Add(oSymbolDef.name)
Next

''[use next line code if you want to pick a symbol from a list in the library]
'oName = InputListBox("Pick a Symbol", oSymbolList, oSymbolList(0), "iLogic", "List of Symbols")

'Tb symbol name must be same name as project number
oName = ProjectNumber

If oName = "" Then
	Return 'exit rule
Else If oName =" " Then
	Return 'exit rule
End If

Dim oSymDef As SketchedSymbolDefinition

'place the symbol in the Drawing Resources folder [i would like to ad to subolder "TB Logo"]
oSymDef = oDrawDoc.SketchedSymbolDefinitions.AddFromLibrary(oSketchSymLib, oName, True)

'coordinate units must be converted to centimeters [WET]
Dim oPosition As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(13.875*2.54, 3.275*2.54)

'[use this if the symbol has no prompted entry
Dim oSymbol As SketchedSymbol
oSymbol = oDrawDoc.ActiveSheet.SketchedSymbols.Add(oSymDef, oPosition, 0, 1, )
']

 

 

Message 4 of 6

A.Acheson
Mentor
Mentor

@wtriplett 

Working with the add folder code in the previous post if you start at this line

Call AddItemsToFolder("Sharps", "Triangle", "Square")

The first string is the folder name and the next strings are the symbols you want to find and add. Because your adding folders you need to work with browser nodes.

Integrating this is new to me so there

may be a cleaner way to approach this. 

I think you will need to keep this code and use it as a private sub to do the folder creation and symbol adding.

As for the symbol deletion I am hoping you can just do a delete symbol and not worry about the folder name. 

A question are you changing the sub folder name? Because when you create the sub folder and save to the symbols library, the folder gets saved too, or you created it in there, I can’t remember. If you want a symbol from within the library the sub folder and symbol gets copied out to the drawing resources folder.
So if your not changing the sub folder name the create folder code is not needed. 

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

A.Acheson
Mentor
Mentor

@wtriplett 

I attempted this last nice and got the folder to be created and deleted but it is a bit of work. It seems that the sub folder is a cosmetic structure and so does not get copied when you copy a symbol. It would need to be created on every symbol that is it used in and deleted once it is empty. Similar to the manual approach already used. I didn’t check if the template had it already would the symbol get dropped into it following the symbol libraries structure. Is the sub folder really required? Could the name be built into the symbol name. And sorted to ensure they stay in a readable order? This would be the easiest to work with as the symbol structure level is flat. 

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

A.Acheson
Mentor
Mentor

@wtriplett 

 See attached Drawing file with code contained as an internal rule. You can use this also as an external rule. I have included some error checking. You will need to modify this further to ensure the correct symbols get deleted and added. The for loop for checking the symbol name might need to be used a couple of times to check the contents of the drawing so might be better placed in a separate sub for convenience.  

 

'Source for adding folder then adding symbols to folder
'https://forums.autodesk.com/t5/inventor-customization/copy-sketched-symbols-with-folders/td-p/713142...
Sub Main
	
'this is the name of the symbol library file,
'the path to this location is specified under 
'Tools tab > Application Options button > Files tab 
Dim oSymbolDrawingName As String
oSymbolDrawingName = "Title Block Sketch Symbols"'Library'Title Block Sketch Symbols

'check file type 
If ThisDoc.Document.DocumentType <> kDrawingDocumentObject Then
Return
End If

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

Dim oSketchSymLib As SketchedSymbolDefinitionLibrary
Try
oSketchSymLib = oDrawDoc.SketchedSymbolDefinitions.SketchedSymbolDefinitionLibraries.Item(oSymbolDrawingName)
Catch
	MessageBox.Show(oSymbolDrawingName & "-Error with Template File name or Location", "iLogic")
	Return
End Try
Dim oSymbol As SketchedSymbol
Dim oFolderTitle As String = "TB Logo"
Dim oSymbolList As New ArrayList


For Each oSymbolDef In oSketchSymLib.SketchedSymbolDefinitions
	oSymbolList.Add(oSymbolDef.name)
	
Next

''[use next line code if you want to pick a symbol from a list in the library]
oName = InputListBox("Pick a Symbol", oSymbolList, oSymbolList(0), "iLogic", "List of Symbols")
If oName = "" Then
	MessageBox.Show("Exiting", "Title")
	Return'exit rule
ElseIf oName = " " Then
	MessageBox.Show("Exiting", "Title")
	Return'exit rule
	
	'Tbe symbol name must be same name as project number
ElseIf oName = iProperties.Value("Custom", "ProjectNumber") Then

 'Check if there is a symbol in the drawing with oName
 	For Each oSymbol In oDrawDoc.ActiveSheet.SketchedSymbols
				'look for the symbol by name
				'deletes all symbols not "oName" Or all symbols = "oName"
				'If oSymbol.Name <> oName Or oSymbol.Name = oName  Then
				
				'Delete if present to ensure only one is added and it is the most uptodate
				 If oSymbol.Name = oName Then
				 'If oSymbol.Name <> Symbol Then
					  oSymbol.Delete
					  MessageBox.Show(oName & "-Symbol has been Deleted from all Active Sheet", "iLogic")
				 End If
		Next
		
	Dim oSymDef As SketchedSymbolDefinition
	'Add the symbol to the drawing
	Try
	oSymDef = oDrawDoc.SketchedSymbolDefinitions.AddFromLibrary(oSketchSymLib, oName, True)
	'Call the sub to add folder and then symbol/symbols to the folder
	Catch
		MessageBox.Show("Symbol All Ready Created,Exiting", "iLogic")
	End Try
	
	Try
	Call AddItemsToFolder(oFolderTitle, oName)
	Call SortDwgResourcesFolder
	Catch
		MessageBox.Show("Folder All Ready Created,Exiting", "iLogic")
	End Try
	
	'coordinate units must be converted to centimeters [WET]
	Dim oPosition As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(13.875*2.54, 3.275*2.54)
	
	Try
	'use this If the symbol has no prompted entry
	oSymbol = oDrawDoc.ActiveSheet.SketchedSymbols.Add(oSymDef, oPosition, 0, 1, )
	Catch
		MessageBox.Show("Symbol All Ready Created,Exiting", "iLogic")
	End Try
	
	
Else
	Try
			 'Check if there is a symbol in the drawing with oName
	 	For Each oSymbol In oDrawDoc.ActiveSheet.SketchedSymbols
					'look for the symbol by name
					'deletes all symbols not "oName" Or all symbols = "oName"
					'If oSymbol.Name <> oName Or oSymbol.Name = oName  Then
					
					'Delete if present to ensure only one is added and it is the most uptodate
					 If oSymbol.Name = oName Then
					 'If oSymbol.Name <> Symbol Then
						  oSymbol.Delete
						  MessageBox.Show(oName & "-Symbol has been Deleted from all Active Sheet", "iLogic")
					 End If
			Next
		
		'Delete the symbol in the Drawing Resources folder
		SymDel = oDrawDoc.SketchedSymbolDefinitions.Item(oName)
		SymDel.Delete
 		MessageBox.Show(oName & "-Symbol has been Deleted from Drawing Resources folder", "iLogic")
		Call DeleteItemsFolder(oFolderTitle)
		MessageBox.Show(oFolderTitle & "-SubFolder has been Deleted from Drawing Resources Folder", "iLogic")
	Catch
		MessageBox.Show("Nothing to delete Exiting", "iLogic")
	End Try
End If
InventorVb.DocumentUpdate()


End Sub


Sub AddItemsToFolder(oFolderTitle As String, ByVal ParamArray oSketchedSymbolNameArray As String())

	Dim oPane As BrowserPane
	Dim oNode As BrowserNode
	Dim oTopNode As BrowserNode
	Dim oDwgResourcesFolder As BrowserNode
	Dim oSketchedSymbolsFolder As BrowserNode
	Dim oOccurrenceNodes1 As ObjectCollection
	
	oOccurrenceNodes1 = ThisApplication.TransientObjects.CreateObjectCollection
	oPane = ThisApplication.ActiveDocument.BrowserPanes("Model")

	oDwgResourcesFolder = oPane.TopNode.BrowserNodes.Item("Drawing Resources")
	oSketchedSymbolsFolder = oDwgResourcesFolder.BrowserNodes.Item(4)
	
	For Each oNode In oSketchedSymbolsFolder.BrowserNodes
		oNodeName = Right(oNode.FullPath, Len(oNode.FullPath) - InStrRev(oNode.FullPath, ":", -1))
		
		For Each oSketchSymbolName In oSketchedSymbolNameArray
			If oNodeName = oSketchSymbolName
				oOccurrenceNodes1.Add(oNode)
			End If
		Next
		
	Next
	
	oPane.AddBrowserFolder(oFolderTitle, oOccurrenceNodes1)
	
End Sub

Sub DeleteItemsFolder(oFolderTitle As String)

	Dim oPane As BrowserPane
	Dim oNode As BrowserNode
	Dim oTopNode As BrowserNode
	Dim oDwgResourcesFolder As BrowserNode
	Dim oSketchedSymbolsFolder As BrowserNode

	
	oPane = ThisApplication.ActiveDocument.BrowserPanes("Model")
	MessageBox.Show(oFolderTitle, "Folder Title")

	oDwgResourcesFolder = oPane.TopNode.BrowserNodes.Item("Drawing Resources")
	oSketchedSymbolsFolder = oDwgResourcesFolder.BrowserNodes.Item(4)
	oSketchedSymbolsSubFolder = oSketchedSymbolsFolder.BrowserFolders.Item(oFolderTitle)
	oSketchedSymbolsSubFolder.Delete
End Sub

Sub SortDwgResourcesFolder()

	ThisApplication.ActiveDocument.BrowserPanes("Model").TopNode.BrowserNodes.Item("Drawing Resources").BrowserNodes.Item(4).DoSelect
	
	Dim oCommandMgr As CommandManager
	oCommandMgr = ThisApplication.CommandManager
	
	Dim oControlDef1 As ControlDefinition
	oControlDef1 = oCommandMgr.ControlDefinitions.Item("DrawingResourceSort")
	oControlDef1.Execute
End Sub

 

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