06-30-2023
06:04 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
06-30-2023
06:04 AM
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:
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 ![]()
Jhoel Forshav
Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website