iLogic Normalise Browser Nodes – With Code

If you’ve ever copied an Inventor assembly using Vault, or other methods, you may have noticed that your iLogic code no longer works as expected. This is most likely because the file names of the component instances have changed in the browser.

In the image below, I have a small assembly (left), it has been copied in Vault (right), the copied components have a new display name in the browser, based on Inventor’s default display.

iLogic uses the browser name for running code. In the image below you can see a part “CSB-MFG-0544”, when copied is is named “CSB-MFG-0544-01” – Highlighted in yellow in the image and shown in 3 occurrences of the same part.

If the iLogic code in the copied assembly is looking for “CSB-MFG-0544”, it will fail, with a similar error to the one above. This is because the new file is now called “CSB-MFG-0544-01“.

Good practice is to rename the browser nodes, this process is also called “Stabilising” or “Normalising” your browser nodes, Gavin Bath does a nice explanation of the “Why?” in this blog post and video.

On to my code. It’s pretty simple, it finds the first instance of a component and renames the browser node (removing the “:1”). When the assembly file is copied, no matter what the new file name of the instance is, the modified “browser node name” will remain, and your code should work.

In this example we are only renaming the first instance, as changing it (via iLogic), will change all other instances automatically, as they are the same file. But there is a version of the code at the bottom of this post that renames all instances (useful for Managed Components).

I’ve placed the rule in an “Undo Wrapper”. When renaming multiple nodes, to undo this, you would need to do multiple “undos” to get back to the original state, the “Undo Wrapper” packages up all of these changes and Inventor recognises them as one transaction, meaning one undo.

The results look like this (note there are only 2 unique files in this assembly):

Here is an animated GIF of the code in action:

Here’s the iLogic Code:

'Code by @ClintBrown3D originally posted here: --> https://clintbrown.co.uk/ilogic-normalise-browser-nodes---with-code
'This iLogic utility "normalises" the first instance of a browser node in an assembly

oDoc = ThisDoc.Document
oNamer = "Normalise Browser Nodes"
Dim UNDO As Transaction 
UNDO = ThisApplication.TransactionManager.StartTransaction(oDoc, oNamer)
'The rule is placed in an "undo wrapper" to it faster to undo the changes to multiple browser node changes
'https://clintbrown.co.uk/2019/03/03/undo/
'----------------------------------------------------------------------------------------------------------------------
Dim doc = ThisDoc.Document : If doc.DocumentType = kAssemblyDocumentObject Then 'Check we are in an IAM
Else : Return :End If

Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
Dim oCompOcc As Inventor.ComponentOccurrence

For Each oCompOcc In oDef.Occurrences
GetOccName = oCompOcc.Name

Try
NewName = (GetOccName.Split(":")(0)) ' Removes ":1" from the Browser Node
oCompOcc.Name = NewName

Catch : End Try : Next
'-------------------------------------------------------------------------------------------------------------------------
UNDO.End

As mentioned above, if you are using “Managed Components”, the names of the secondary, tertiary etc. occurrences becomes important, and a recognisable name (by your iLogic code) for these is needed. To that end, I have another version of the code, that adds an underscore and the occurrences number to the browser node, for example, if a component (Part007) is the 15th browser entry, it’s node will be renamed to Part007_15.

Here is the iLogic code:

'Code by @ClintBrown3D originally posted here: --> https://clintbrown.co.uk/ilogic-normalise-browser-nodes---with-code
'This iLogic utility "normalises" the first instance of a browser node in an assembly

oDoc = ThisDoc.Document
oNamer = "Normalise Browser Nodes"
Dim UNDO As Transaction 
UNDO = ThisApplication.TransactionManager.StartTransaction(oDoc, oNamer)
'The rule is placed in an "undo wrapper" to it faster to undo the changes to multiple browser node changes
'https://clintbrown.co.uk/2019/03/03/undo/
'----------------------------------------------------------------------------------------------------------------------
Dim doc = ThisDoc.Document : If doc.DocumentType = kAssemblyDocumentObject Then 'Check we are in an IAM
Else : Return :End If

Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
Dim oCompOcc As Inventor.ComponentOccurrence

OccCounter = 0
For Each oCompOcc In oDef.Occurrences
GetOccName = oCompOcc.Name
OccCounter = OccCounter + 1

Try
NewName = (GetOccName.Split(":")(0)) ' Removes ":1" from the Browser Node
oCompOcc.Name = NewName & "_" & OccCounter

Catch : End Try : Next
'-------------------------------------------------------------------------------------------------------------------------
UNDO.End

Update: 4th August 2020 – Code to include sub assembly occurrences

'Code by @ClintBrown3D originally posted here: --> https://clintbrown.co.uk/ilogic-normalise-browser-nodes---with-code
'This iLogic utility "normalises" the first instance of a browser node in an assembly

oDoc = ThisDoc.Document
oNamer = "Normalise Browser Nodes"
Dim UNDO As Transaction 
UNDO = ThisApplication.TransactionManager.StartTransaction(oDoc, oNamer)
'The rule is placed in an "undo wrapper" to it faster to undo the changes to multiple browser node changes
'https://clintbrown.co.uk/2019/03/03/undo/
'----------------------------------------------------------------------------------------------------------------------
Dim doc = ThisDoc.Document : If doc.DocumentType = kAssemblyDocumentObject Then 'Check we are in an IAM
Else : Return :End If

Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
Dim oCompOcc As Inventor.ComponentOccurrence

OccCounter = 0
For Each oCompOcc In oDef.Occurrences
GetOccName = oCompOcc.Name
OccCounter = OccCounter + 1
SubOccCount = 0

Try
	'Top Level Occurrences
NewName = (GetOccName.Split(":")(0)) ' Removes ":1" from the Browser Node
oCompOcc.Name = NewName & "_" & OccCounter

'Sub level Occurrences
   For Each oSubOcc As ComponentOccurrence In oCompOcc.SubOccurrences
	   SubOccCount = SubOccCount + 1
	   SubNewName = (oSubOcc.Name.Split(":")(0))
   oSubOcc.Name = SubNewName & "_" & SubOccCount
   Next
   
Catch : End Try : Next
'-------------------------------------------------------------------------------------------------------------------------
UNDO.End

Notes:

This version of the code was briefly tested in Inventor 2021.

As always, please test all iLogic code extensively on non-production files. Do not use any code in a production environment until YOU have thoroughly tested it and have verified that it works as expected. Always back up any data before running any experimental code. You are ultimately responsible for any iLogic code that you run, so make sure you test it thoroughly!