06-30-2023
03:56 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
06-30-2023
03:56 AM
Thank you for the answer.
Here is the result (components are partially renamed) :
And in fact the program is aborted by this error
The code modified as you suggest :
Sub Main If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then MsgBox("An Assembly Document must be active for this rule to work. Exiting.",vbOKOnly+vbCritical, "WRONG DOCUMENT TYPE") Exit Sub End If Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition 'Dim oOcc As ComponentOccurrence 'Start a Transaction to bundle all the name changes into a single item in the 'Undo' menu. Dim oTransaction As Transaction = ThisApplication.TransactionManager.StartTransaction(oADoc, "Rename Components") 'rename all comps in top level first For Each oOcc In oADef.Occurrences RenameOcc(oOcc) Next 'now try to rename comps at deeper levels For Each oOcc As ComponentOccurrence In oADef.Occurrences.AllReferencedOccurrences(asmDef).OfType(Of ComponentOccurrence) RenameOcc(oOcc) Next 'end the Transaction oTransaction.End End Sub
You can find the assembly in the link below.