Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

I just made a more robust rule that also renames the occurrences in order in the tree. Tried it on an Assembly containing both iParts and iAssemblies and it works well for me:
forumBild.png

Class ThisRule
	Dim name As String = "Part"
	Dim num As Integer = 1
	Dim existingOccs As ComponentOccurrencesEnumerator
	Sub Main
		Dim def As AssemblyComponentDefinition = ThisDoc.Document.ComponentDefinition
		existingOccs = def.Occurrences.AllReferencedOccurrences(def)
		For Each oOcc As ComponentOccurrence In def.Occurrences
			TraverseAndSetNames(oOcc)
		Next
	End Sub
	Sub RenameExisting(oName As String)
		Dim existingOccWithName As ComponentOccurrence = existingOccs.OfType(Of ComponentOccurrence).FirstOrDefault(Function(x) x.Name = oName)
		If existingOccWithName IsNot Nothing
			existingOccWithName.Name = oName & "_old"
		End If
	End Sub
	Sub RenameOcc(oOcc As ComponentOccurrence)
		oOcc.Name = name & num
		num += 1
	End Sub
	Sub TraverseAndSetNames(oOcc As ComponentOccurrence)
		RenameExisting(name & num)
		RenameOcc(oOcc)
		If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject
			For Each sOcc As ComponentOccurrence In oOcc.SubOccurrences
				TraverseAndSetNames(sOcc)
			Next
		End If
	End Sub
End Class

 Let me know if it works for you or if I've misunderstood what you're trying to do :slightly_smiling_face: