Hi @karram . Please try this code:
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
If oCompCopy.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Or _
oCompCopy.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject Then GoTo Step1Rule
Loop
Step1Rule :
Do
oCompPaste = oCM.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Select component paste params...")
If oCompPaste Is Nothing Then Exit Sub
If oCompPaste.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Or _
oCompPaste.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject Then GoTo Step2Rule
Loop
Step2Rule :
Dim oCopyDoc As Document = oCompCopy.Definition.Document
Dim oCopyProperty As PropertySet = oCopyDoc.PropertySets.Item("Inventor User Defined Properties")
Dim oPasteDoc As Document = oCompPaste.Definition.Document
Dim oPasteProperty As PropertySet = oPasteDoc.PropertySets.Item("Inventor User Defined Properties")
Dim newTM As Transaction = oTm.StartTransaction(oADoc, "CopingUserProperty")
Call CreateParamsInAssembly(oPasteProperty, oCopyProperty)
newTM.End()
oADoc.Update()
Else
MessageBox.Show("Active document is not AssemblyDocument.", "Error!",MessageBoxButtons.OK,MessageBoxIcon.Error)
End If
End Sub
Private Function CreateParamsInAssembly(oPasteProperty As PropertySet, ByVal oCopyProperty As PropertySet)
Dim bCreatProp As Boolean
For Each copyProp As Inventor.Property In oCopyProperty
bCreatProp = True
For Each oProp As Inventor.Property In oPasteProperty
If oProp.Name = copyProp.Name Then
bCreatProp = False
oProp.Value = copyProp.Value
End If
Next
If bCreatProp Then
oPasteProperty.Add(copyProp.Value, copyProp.Name, copyProp.PropId)
End If
Next
End Function