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

@JhoelForshav  have right that reason must be in missing parameter from expression.

 

If you really must add expression then you can start with this code if you want to determine wchich parameter missing:

 

Dim asmDoc As Inventor.AssemblyDocument = ThisDoc.Document	
Dim refDocUserParams As UserParameters = asmDoc.ComponentDefinition.Parameters.UserParameters
For Each refDoc As Inventor.Document In asmDoc.AllReferencedDocuments

	'Look for part documents.
	'If refDoc.DocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject Then
    	Dim partDoc As Inventor.Document = refDoc
        '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
            	checkParam = Nothing
            End Try

            If checkParam Is Nothing Then
				   
				'Create the missing parameter.
				Dim checkParamdependants As Parameter = Nothing 
					Dim pardependants As String = ""
				
					
					For Each param As Parameter In refDoc.ComponentDefinition.Parameters
						If param.Type <> 50348800 Then
							If param.Dependents.count>0 Then
						For Each paramdep As Parameter In param.Dependents
						If paramdep.name = partUserParam.Name Then
					Try
			            	checkParamdependants = refDocUserParams.Item(param.Name)
			            Catch
							
			            '	If pardependants.Contains(param.name)=False Then
							pardependants = pardependants  & param.name & ";"
					'	End If
			            End Try
					End If
					Next
				End If
				End If
				Next
			Try
			If pardependants = "" Then
				refDocUserParams.AddByExpression(partUserParam.Name, partUserParam.Expression, partUserParam.Units)
			Else
				MessageBox.Show("Error, in assembly dependant parameters missing: " & pardependants)
			End If
			Catch
			 MessageBox.Show ("Error, in assembly dependant parameters missing: " & pardependants )
				End Try
			Else
            	'Update the value of the existing parameter.
				Try
            	checkParam.Expression = partUserParam.Expression
				Catch
				checkParam.Value = partUserParam.Value
			End Try
            End If
		Next
'	End If
Next