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. You need to select 2 assemblage either in the model or in the browser. The first click on the assembly from which you will copy parameters, the second click on the assembly in which you will create parameters.

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 assembly copy params...")
			If oCompCopy Is Nothing Then Exit Sub
		Loop While oCompCopy.DefinitionDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject
		Do
			oCompPaste = oCM.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Select assembly paste params...")
			If oCompPaste Is Nothing Then Exit Sub
		Loop While oCompCopy.DefinitionDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject
		Dim newTM As Transaction = oTm.StartTransaction(oADoc, "CreateUserParameters")
		Dim listParams As New List(Of UserParameter)	
		listParams = GetListParams(oCompCopy.Definition.Parameters)
		Call CreateParamsInAssembly(oCompPaste.Definition.Parameters, listParams)
		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 listParams As List(Of UserParameter))
	Dim bCreatParam As Boolean = True
	For i As Integer = 1 To listParams.Count
		For Each oParam As UserParameter In oParams.UserParameters
			If oParam.Name = listParams.Item(i - 1).Name Then
				bCreatParam = False
				Try
					oParam.Value = listParams.Item(i - 1).Value
				Catch
					oParam.Expression = listParams.Item(i - 1).Expression
				End Try
			End If
		Next
		If bCreatParam Then
			oParams.UserParameters.AddByExpression(listParams.Item(i - 1).Name, listParams.Item(i - 1).Expression, listParams.Item(i - 1).Units)
		End If
	Next i
	
End Function

Private Function GetListParams(ByVal oParams As Parameters) As List(Of UserParameter)
	Dim listParams As New List(Of UserParameter)
	For Each oParam As UserParameter In oParams.UserParameters
		listParams.Add(oParam)
	Next
	Return listParams
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