Hi @ppolcynBNVFN. What you are asking for is fairly complicated, because there are many different types of features and/or sketches, or other things that might be present in the model browser tree. There is a built-in system for adding that number after the name, and we do not have access to that built-in system. So, you would have to be able to recognize the Type of each object, then keep track of every one of that Type of object you find, so you can keep all the numbering sequence for that one specific Type together, and keep track of each sequence place for each Type as you go. That is many layers of complication. I created an iLogic rule that you can try out for renaming generic PartFeatures and PlanarSketches in a part. I did not have a change to fully test this code yet, because I'm about to leave for the day, but here it is below. I did not take the time to put comments into it due to the time restriction, so if you have questions, I may have to answer them next week.
Sub Main
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then
MsgBox("A Part Document must be active for this rule to work. Exiting.", vbCritical, "")
Exit Sub
End If
Dim oPDoc As PartDocument = ThisDoc.Document
RenameFeaturesInSequence(oPDoc)
RenameSketchesInSequence(oPDoc)
End Sub
Sub RenameFeaturesInSequence(oPartDoc As Document)
If IsNothing(oDoc) OrElse oDoc.IsModifiable = False Then Exit Sub
Dim oPDef As PartComponentDefinition = oPartDoc.ComponentDefinition
Dim oFeats As PartFeatures = oPDef.Features
Dim oDict As New Dictionary(Of String, List(Of PartFeature))
For Each oFeat As PartFeature In oFeats
Dim oType As String = System.Enum.GetName(GetType(ObjectTypeEnum), oFeat.Type)
oType = Replace(Right(oType, oType.Length - 1), "Object", "")
If oDict.Keys.Contains(oType) = False Then
oDict.Add(oType, New List(Of PartFeature) From {oFeat })
Else
If oDict.Item(oType).Contains(oFeat) = False Then
oDict.Item(oType).Add(oFeat)
End If
End If
Next
If IsNothing(oDict) OrElse oDict.Count = 0 Then Exit Sub
For Each oPair In oDict
If oPair.Value.Count = 0 Then Continue For
Dim oInt As Integer = 0
For Each oPartFeat In oPair.Value
oInt = oInt + 1
oPartFeat.Name = oPair.Key & oInt
Next
Next
End Sub
Sub RenameSketchesInSequence(oPartDoc As Document)
If IsNothing(oDoc) OrElse oDoc.IsModifiable = False Then Exit Sub
Dim oPDef As PartComponentDefinition = oPartDoc.ComponentDefinition
Dim oSketches As PlanarSketches = oPDef.Sketches
Dim oDict As New Dictionary(Of String, List(Of PlanarSketch))
Dim oType As String = "PlanarSketch"
For Each oSketch As PlanarSketch In oSketches
If oDict.Count = 0 Then
oDict.Add(oType, New List(Of PlanarSketch) From {oSketch})
Else
If oDict.Item(oType).Contains(oSketch) = False Then
oDict.Item(oType).Add(oSketch)
End If
End If
Next
If IsNothing(oDict) OrElse oDict.Count = 0 Then Exit Sub
For Each oPair In oDict
If oPair.Value.Count = 0 Then Continue For
Dim oInt As Integer = 0
For Each oSk In oPair.Value
oInt = oInt + 1
oSk.Name = oPair.Key & oInt
Next
Next
End Sub
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

(Not an Autodesk Employee)