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

Try this code:

 

Sub main
	Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
	Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
	Dim oPane As BrowserPane = oDoc.BrowserPanes.Item("Model")
	Dim oOccs As ComponentOccurrences = oDef.Occurrences
	Dim oTM As Transaction = ThisApplication.TransactionManager.StartTransaction(oDoc, "Explode Assembly")
	ReturnStep :
	For Each oOcc As ComponentOccurrence In oOccs
		Dim oRefDoc As Document = oOcc.Definition.Document
		If oRefDoc.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject _
			Or Not oRefDoc.IsModifiable Then Continue For
		Dim oTargetNode As BrowserNode = oPane.GetBrowserNodeFromObject(oOcc)
		For Each oSubOcc As ComponentOccurrence In oOcc.SubOccurrences
			If oSubOcc.DefinitionDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
				Try : oSubOcc.Name = oOcc.Name & " - " & oSubOcc.Name :	Catch : End Try
			End If
		    Dim oSourceNode As BrowserNode
		    oSourceNode = oPane.GetBrowserNodeFromObject(oSubOcc)
		    Try : Call oPane.Reorder(oTargetNode, True, oSourceNode) : Catch : End Try
		Next
		oOcc.Delete()
	Next
	If HasSubAsm(oOccs) Then GoTo ReturnStep
	oTM.End()
End Sub

Private Function HasSubAsm(ByVal oOccs As ComponentOccurrences) As Boolean
	For i As Integer = 1 To oOccs.Count
		If oOccs(i).DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then Return True
	Next i
	Return False
End Function

 

The new name of the component is written in line 15.

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature