Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
philippe.lagrue
in reply to: ts2.cad3

Thank you for the answer.

Here is the result (components are partially renamed) :

2023-06-30_12h40_13.jpg

And in fact the program is aborted by this error

2023-06-30_12h38_31.jpg

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.