@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.