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

iLogic copy user parameters from parts to assembly

Using iLogic, I want to be able to copy user parameters from part files into an assembly. I found an example that copies user parameters from an assembly into part files and tried modifying it to suit my needs and it runs without errors but does not copy over any of the user parameters. The code I have is below.

 

Dim asmDoc As Inventor.AssemblyDocument = ThisDoc.Document	

For Each refDoc As Inventor.Document In asmDoc.AllReferencedDocuments

	'Look for part documents.
	If refDoc.DocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject Then
    	Dim partDoc As Inventor.PartDocument = refDoc
    	Dim refDocUserParams As UserParameters = refDoc.ComponentDefinition.Parameters.UserParameters

        'Add the part parameters to the assembly.
        For Each partUserParam As UserParameter In refDoc.ComponentDefinition.Parameters.UserParameters
            'Check to see if the parameter already exists.
            Dim checkParam As UserParameter = Nothing
            Try
            	checkParam = refDocUserParams.Item(partUserParam.Name)
            Catch ex As Exception
            	checkParam = Nothing
            End Try

            If checkParam Is Nothing Then
				'Create the missing parameter.
            	refDocUserParams.AddByExpression(partUserParam.Name, partUserParam.Expression, partUserParam.Units)
			Else
            	'Update the value of the existing parameter.
            	checkParam.Expression = partUserParam.Expression
            End If
		Next
	End If
Next

 Any help with what I am doing wrong is appreciated.