To copy parameters from one to another by clicking in assembly

To copy parameters from one to another by clicking in assembly

RoyWickrama_RWEI
Advisor Advisor
456 Views
2 Replies
Message 1 of 3

To copy parameters from one to another by clicking in assembly

RoyWickrama_RWEI
Advisor
Advisor

By running the rule in assembly, I need to copy selected parameters from one part to another selected in an assembly with the following rule.

It does not copy the expression. I request someone help. Sample files attached.

 

2020-01-11 22_05_00-Edit Rule_ Copy User Params from Another.png

 

 

 

 

Public Sub Main()
    If ThisDoc.Document.DocumentType <> Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then
        MsgBox("The active document must be an assembly.")
        Return
    End If
	CopyUserParams()
	oUpdate()
End Sub

Private Sub CopyUserParams()
Dim oOcc1 As ComponentOccurrence
oOcc1 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Select Doc 1")
oOcc1_Selected = oOcc1

If oOcc1_Selected Is Nothing Then Exit Sub
Dim oDoc1_Selected As Document = oOcc1_Selected.Definition.Document
Dim oDoc1_UserParams As UserParameters = oDoc1_Selected.ComponentDefinition.Parameters.UserParameters
oDoc1_UserParams = oDoc1_Selected.ComponentDefinition.Parameters.UserParameters


Dim oUserParams_oOcc1_Selected As New ArrayList
For Each oListParams_oOcc1 In oDoc1_UserParams
		'MessageBox.Show("oListParams_oOcc1: " & oListParams_oOcc1.Name, "Title")
	If oListParams_oOcc1.Name.Contains("Stairs") Then
	oUserParams_oOcc1_Selected.Add(oListParams_oOcc1.Name)		

	End If
Next oListParams_oOcc1

Dim oOcc2 As ComponentOccurrence
oOcc2 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Select Doc 2")
oOcc2_Selected = oOcc2
If oOcc2_Selected Is Nothing Then Exit Sub
Dim oDoc2_Selected As Document = oOcc2_Selected.Definition.Document
Dim oDoc2_UserParams As UserParameters = oDoc2_Selected.ComponentDefinition.Parameters.UserParameters
oDoc2_UserParams = oDoc2_Selected.ComponentDefinition.Parameters.UserParameters


            ' Add the assembly parameters to the part.
'            For Each oUserParam_oOcc1 As UserParameter In oDoc1_UserParams	'asmDoc.ComponentDefinition.Parameters.UserParameters
            For Each oUserParam_oOcc1_Selected In oUserParams_oOcc1_Selected	'asmDoc.ComponentDefinition.Parameters.UserParameters
				oAvail = "No"
					For Each oUserParam_oOcc2 As UserParameter In oDoc2_UserParams
						'MessageBox.Show("oUserParam_oOcc2.Name): " & oUserParam_oOcc2.Name, "Title")
						If oUserParam_oOcc2.Name = oUserParam_oOcc1_Selected Then
							oAvail = "Yes"
							Exit For
						Else
							
						End If

					Next oUserParam_oOcc2
				
				If oAvail = "No" Then
					MessageBox.Show("@ No" _
					& vbLf & "oName: " & oUserParam_oOcc1_Selected _
					& vbLf & "oExpression: " & oDoc1_UserParams.Item(oUserParam_oOcc1_Selected).Expression _
					& vbLf & "Units: " & oDoc1_UserParams.Item(oUserParam_oOcc1_Selected).Units, "Title")
					oName = oUserParam_oOcc1_Selected
					oExpression = oDoc1_UserParams.Item(oUserParam_oOcc1_Selected).Expression
					oUnits = oDoc1_UserParams.Item(oUserParam_oOcc1_Selected).Units
					oDoc2_UserParams.AddByExpression(oName, oExpression, oUnits)
				Else If oAvail = "Yes" Then
					MessageBox.Show("@ YES: " & oUserParam_oOcc1_Selected, "Title")

					 oDoc2_UserParams.Item(oUserParam_oOcc1_Selected).Expression = oDoc1_UserParams.Item(oUserParam_oOcc1_Selected).Expression
				End If
            Next oUserParam_oOcc1_Selected
End Sub


Sub oUpdate()

End Sub
0 Likes
457 Views
2 Replies
Replies (2)
Message 2 of 3

RoyWickrama_RWEI
Advisor
Advisor

Looking forward to receive help.

0 Likes
Message 3 of 3

WCrihfield
Mentor
Mentor

Why use the lines "oOcc1_Selected = oOcc1" and "oOcc2_Selected = oOcc2" instead of continuing to use oOcc1 and oOcc2?  oOcc1 and oOcc2 have already defined as a ComponentOccurrence.

Also I noticed you defined oDoc1_UserParams twice and oDoc2_UserParams twice.  Propably doesn't hurt anything though.

Are you seeing the rest of the MessageBox info you're expecting up to that point in the code?

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes