iLogic to Rename Browser Nodes to "Default" setting?

iLogic to Rename Browser Nodes to "Default" setting?

mtresky
Contributor Contributor
733 Views
5 Replies
Message 1 of 6

iLogic to Rename Browser Nodes to "Default" setting?

mtresky
Contributor
Contributor

Hi, I am trying to automate the renaming of browser nodes to the default setting (see screen shot below).

I know how to cycle through nodes and rename them, but I am hoping there is a way to run the command which already does this?  For the user to do this, it is 5-6 mouse clicks, just looking for a way to fire this at the end of a rule to automatically reset to default setting for them.

 

mtresky_0-1702913200068.png

 

0 Likes
Accepted solutions (1)
734 Views
5 Replies
Replies (5)
Message 2 of 6

yuzeaa
Advocate
Advocate
Accepted solution

Just need to set it's name empty.

For Each occ As ComponentOccurrence In ThisApplication.ActiveDocument.ComponentDefinition.Occurrences
	occ.Name = ""
Next
Message 3 of 6

mtresky
Contributor
Contributor
Thank you, that resolved it!
Message 4 of 6

christian_horstGMMED
Explorer
Explorer

This is great! Is there a simalarly simple line of code to seledt "Part Number" instead of the "default"? So I am looking for something like:

 

For Each occ As ComponentOccurrence In ThisApplication.ActiveDocument.ComponentDefinition.Occurrences
	occ.Name = "Part Number"
Next

 

0 Likes
Message 5 of 6

WCrihfield
Mentor
Mentor

Hi @christian_horstGMMED.  Try this:

Dim oADoc As AssemblyDocument = TryCast(ThisDoc.Document, Inventor.AssemblyDocument)
If oADoc Is Nothing Then Return
For Each oOcc As ComponentOccurrence In oADoc.ComponentDefinition.Occurrences
	Dim sPN As String = iProperties.Value(oOcc.Name, "Project", "Part Number")
	Try
		oOcc.Name = sPN
	Catch
		Logger.Error("Could not rename component named: " & oOcc.Name _
		& vbCrLf & "to: " & sPN)
	End Try
Next
oADoc.Update2(True)

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 6

WCrihfield
Mentor
Mentor

@christian_horstGMMED.  Renaming all assembly components in a large assembly can be a lot more complex than you might expect, because no two component occurrences can have exactly the same name, which is why they automatically put the ":" character, followed by an index Integer, at the end of every occurrence name in the model browser.  So, if your assembly has more than one occurrence in it that is referencing the same source model document file, or another one with the same Part Number value, then the simplistic code example above will not work, because it will be trying to name all occurrences with the same part number value the same.  Attached is a text file containing some code for a far more complex and intuitive iLogic rule example, with error avoidance measures and feedback built into it, for a task like this.  I already had a similar code in my custom snippets from another case at some point, so I just updated it a bit.  The code is broken up into 3 routines.  The 'Main' routine gets the assembly document, attempts to group all of its components by their Part Number values with a second routine, then uses the third routine to try to rename all of them by their Part Numbers, with an Index system applied, per Part Number group.  Although its second routine is set-up to 'Optionally' work recursively, its actions should not effect any of the assembly's referenced documents, just the names of the occurrences, as seen in the model browser tree from the perspective of the main assembly.  And its actions should be easy to undo with a single click on the undo button.  So, if the simplistic example above does not work for you, you can give this one a try.  I have not tested it yet, so you may want to review its contents first, then test on unimportant files first.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes