Rename browser nodes by Description iProperty

Rename browser nodes by Description iProperty

mtmarchant
Advocate Advocate
814 Views
8 Replies
Message 1 of 9

Rename browser nodes by Description iProperty

mtmarchant
Advocate
Advocate

I've searched the forums and Google extensively, and have yet to come up with a 100% working setup in which I can rename browser nodes based on their description, as defined in the individual file's iProperties. 

 

There have been a few instances where I have been able to get an iLogic rule to work, however generally it is on very simple assemblies (1-10 individual files), and anything more the rule errors out. I've also looked at the Macros and VBA Editor, though I am very unfamiliar with these and I have yet to have a working setup for those.

 

Has anyone successfully done this, and willing to share?

Mack Marchant - Project Engineer
0 Likes
Accepted solutions (1)
815 Views
8 Replies
Replies (8)
Message 2 of 9

WCrihfield
Mentor
Mentor

Generally speaking, the usual problem with renaming browser nodes to iProperty values, is that you may have the same document multiple times in an assembly (as components), each with the same iProperty values, but each component occurrence must have a unique name in the browser.  You almost always have to create an incremental naming system for when the browser name you are attempting to assign is already being used, so it will slightly modify its name, one way or another.  The most common routine places an Integer at the end of the browser node name when that name is already used, and increment that Integer by one, for each additional time it tries to use that name.  I'm sure there are several ways to do this.  What are your preferences/needs in detail for this task?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 9

mtmarchant
Advocate
Advocate

Our team is really looking at utilizing the descriptions iProperty as a quick way to check the component files in an assembly (as we are using an auto-numbering file system in conjunction with Vault). Inventor has the built-in Rename Model Nodes function, however it doesn't include the options to sort by Descriptions in that function. I understand that complications can/will arise whenever two files share the same description, and a sequential numbering system would be required to combat those occurrences. I will attach the iLogic rule that I have managed to get working on our smaller assemblies. I have gotten this code from other forum posts here, and am still learning as to what the different code functions pertain to and do.

Mack Marchant - Project Engineer
0 Likes
Message 4 of 9

J-Camper
Advisor
Advisor

@mtmarchant,

I cleaned up a little bit of the code, and added a NameThis Sub routine which will increment for duplicated Description values.  Here is modified code:

Sub Main()
	'Grab the Assembly Document. only sufficient for local i logic rules.
	Dim oDoc As AssemblyDocument = ThisDoc.Document
	Dim ThisPath As String = oDoc.FullFileName
	
	'Grab the Active Assembly Component Definition
	Dim oAsmCompDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
	
	' Get the model browser
	Dim oPane As BrowserPane = oDoc.BrowserPanes.Item("Model")
	Dim AssySubtype As String = "Assembly"
	
	'Loop through first level occurrences only
	For Each oOcc As ComponentOccurrence In oDoc.ComponentDefinition.Occurrences 
	    'Grab Document from Occurrence    
	    Dim oOccDoc As Document = oOcc.Definition.Document
		
	    'get design properties set'    
	    Dim invDesignInfo As PropertySet = oOccDoc.PropertySets.Item("Design Tracking Properties")
		
	    ' Get the Description property.
	    Dim invDescriptionProperty As Inventor.Property = invDesignInfo.Item("Description")
		
		'Get reference information for the path for the purpose of checking for whether the component is a standard Content Center part
		Dim PathProperty As String = "ReferencePath"
		Dim oPath As String = oOccDoc.FullFileName
		
		'Create a property that can be referenced later for the purpose of maintaining links in other iLogic commands
		Dim customPropSet As PropertySet = oOccDoc.PropertySets.Item("Inventor User Defined Properties")
		Dim PropertyName As String = "ReferenceBrowserName"
		
		'Checks to see if the component is a standard content center part
		If InStr(oPath, "Content Center Files") >= 1 Then Continue For 'skips contentcenter files by path
		
		'Checks to see if the component is actually the parent level assembly.  This is necessary when the active assembly is a weldment
		If InStr(oPath, ThisPath) >= 1 Then Continue For 'skips main assembly by path

		'Enter Try Catch
		Try 'Test to see if the property, "ReferencePath" has already been created
			custompath = customPropSet.Item(PathProperty)
		Catch 'If it hasn't been created, do so
			customPropSet.Add(oPath, PathProperty)
		End Try
    	
		' Get the browser node that corresponds to the new item
   		Dim oSubAssyNode As BrowserNode = oPane.GetBrowserNodeFromObject(oOcc)
		
		'Take the current name of the component and separate it from the ":XX" instance number
		Dim CurrentNode() As String
		CurrentNode = oOcc.Name.Split({":"c }, StringSplitOptions.None)
		'Logger.Trace(CurrentNode(0))
		
		'Determine whether the browser node should be renamed
		If String.Compare(CurrentNode(0),(invDescriptionProperty.Value), True) = 0 Then
			'If everything is consistent, then do nothing
		Else
			Try
   				prop = customPropSet.Item(PropertyName)
			Catch
				customPropSet.Add(CurrentNode(0), PropertyName)
			End Try	
       		'Set The name   
       		Call NameThis(oSubAssyNode, (invDescriptionProperty.Value))' & InstNum)
		End If
	Next
End Sub 

Sub NameThis(MyNode As BrowserNode, NewName As String)
	Dim SetName As String = NewName
	Dim Attempt As Integer = 1
NameAttempt:
	Try
		MyNode.NativeObject.Name = SetName
	Catch
		If Attempt = 1 Then Attempt += 1 : SetName = SetName & "_" & Attempt : GoTo NameAttempt
		If Attempt > 50 Then Exit Sub 'limit attempts to 50 instances of the same part
		'Once here we need to edit the number
		Attempt += 1
		SetName = Left(SetName, NewName.Length + 1) & Attempt
		GoTo NameAttempt
	End Try
End Sub

 

Let me know if you have any questions, or if this is not working as intended.

Message 5 of 9

JelteDeJong
Mentor
Mentor

I see that @J-Camper  already responded while I was working on a solution. For what it's worth here is what I came up with. (it was already finished)

Public Class ThisRule
    Private _counter As Integer = 1
    Sub Main()
        Dim doc As AssemblyDocument = ThisDoc.Document
        Dim oPane As BrowserPane = doc.BrowserPanes.Item("Model")
        findNodesRecursive(oPane.TopNode)
    End Sub

    Private Sub findNodesRecursive(node As BrowserNode)
        setNodeName(node)
        For Each subNode As BrowserNode In node.BrowserNodes
            findNodesRecursive(subNode)
        Next
    End Sub

    Private Sub setNodeName(node As BrowserNode)
        Try
            If (node.NativeObject Is Nothing) Then Return
            If (Not TypeOf (node.NativeObject) Is ComponentOccurrence) Then
                Return
            End If
            Dim occ As ComponentOccurrence = node.NativeObject
            Dim doc As Document = occ.Definition.Document
            Dim propSet As PropertySet = doc.PropertySets.Item("Design Tracking Properties")
            Dim propDescription As [Property] = propSet.Item("Description")
            occ.Name = String.Format("{0}:{1}", propDescription.Value, _counter)
            _counter = _counter + 1
        Catch ex As Exception
        End Try
    End Sub
End Class

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 6 of 9

mtmarchant
Advocate
Advocate

Both @J-Camper and @JelteDeJong solutions appear to be working as intended. I appreciate the input from each of you.

 

Do you all have experience with setting up triggers, so that say, for example, whenever the document is opened, the rule is automatically ran? 

Mack Marchant - Project Engineer
0 Likes
Message 7 of 9

JelteDeJong
Mentor
Mentor
Accepted solution

If you change the rule a bit like this and save it as an external rule:

Public Class ThisRule
    Private _counter As Integer = 1
    Sub Main()
        If (ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject) Then
            Return
        End If
        Dim doc As AssemblyDocument = ThisDoc.Document
        Dim oPane As BrowserPane = doc.BrowserPanes.Item("Model")
        findNodesRecursive(oPane.TopNode)
    End Sub

    Private Sub findNodesRecursive(node As BrowserNode)
        setNodeName(node)
        For Each subNode As BrowserNode In node.BrowserNodes
            findNodesRecursive(subNode)
        Next
    End Sub

    Private Sub setNodeName(node As BrowserNode)
        Try
            If (node.NativeObject Is Nothing) Then Return
            If (Not TypeOf (node.NativeObject) Is ComponentOccurrence) Then
                Return
            End If
            Dim occ As ComponentOccurrence = node.NativeObject
            Dim doc As Document = occ.Definition.Document
            Dim propSet As PropertySet = doc.PropertySets.Item("Design Tracking Properties")
            Dim propDescription As [Property] = propSet.Item("Description")
            occ.Name = String.Format("{0}:{1}", propDescription.Value, _counter)
            _counter = _counter + 1
        Catch ex As Exception
        End Try
    End Sub
End Class

and then use the event trigger "After open document"

JelteDeJong_0-1635193875809.png

I think it should work

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 8 of 9

mtmarchant
Advocate
Advocate

Yep, that worked. Thank you for the help! I intend on studying y'all's programs so that I can more easily troubleshoot this kind of stuff in the future. Appreciate it!

Mack Marchant - Project Engineer
0 Likes
Message 9 of 9

greggeorgi
Contributor
Contributor

Hi,

 

To you or anyone else that may desire this functionality:

 

If you actively use Autodesk Vault, then the inventor vault integration provides a simple, unique solution. The only caveat is that you have to check-in files to see any changes and obviously it only shows in the vault tab. But it can also show other properties if you are willing to horizontal scroll for them. A benefit with this solution is that it works in drawings/presentations where the browser nodes cannot be renamed.

 

greggeorgi_0-1635335441538.png

 

0 Likes