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

Hi @karram . Try this code. It can copy in any combination: Assembly - Assembly, Assembly - Detail, Detail - Detail, Detail - Assembly.

 

 

Sub main
	Dim oDoc As Document = ThisApplication.ActiveDocument
	If TypeOf oDoc Is AssemblyDocument Then
		Dim oCM As CommandManager = ThisApplication.CommandManager
		Dim oTm As TransactionManager = ThisApplication.TransactionManager
		Dim oADoc As AssemblyDocument = oDoc
		Dim oCompCopy, oCompPaste As ComponentOccurrence
		Do
			oCompCopy = oCM.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Select component copy params...")
			If oCompCopy Is Nothing Then Exit Sub
		Loop While Not oCompCopy.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Or _
			oCompCopy.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject
		Do
			oCompPaste = oCM.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Select component paste params...")
			If oCompPaste Is Nothing Then Exit Sub
		Loop While Not oCompPaste.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Or _
			oCompPaste.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject
		Dim newTM As Transaction = oTm.StartTransaction(oADoc, "CopingUserParameters")
		Call CreateParamsInAssembly(oCompPaste.Definition.Parameters, oCompCopy.Definition.Parameters)
		newTM.End()
		oADoc.Update()
	Else
		MessageBox.Show("Active document is not AssemblyDocument.", "Error!",MessageBoxButtons.OK,MessageBoxIcon.Error)
	End If
End Sub

Private Function CreateParamsInAssembly(oParams As Parameters, ByVal copyParams As Parameters)
	Dim bCreatParam As Boolean
	For Each copyParam As UserParameter In copyParams.UserParameters
		bCreatParam = True
		For Each oParam As UserParameter In oParams.UserParameters
			If oParam.Name = copyParam.Name Then
				bCreatParam = False
				Try
					oParam.Value = copyParam.Value
				Catch
					oParam.Expression = copyParam.Expression
				End Try
			End If
		Next
		If bCreatParam Then
			oParams.UserParameters.AddByExpression(copyParam.Name, copyParam.Expression, copyParam.Units)
		End If
	Next
End Function

  

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