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

@ngnam1988 

 

I typically just use a try/catch to try and set the value, and then catch the error when it does not exist and add it.

 

Keep in mind that drawings and models have the user parameter set organized a bit differently, since drawings do not contain a component definition.

 

If Thisapplication.ActiveDocument.DocumentType = DocumentTypeenum.kDrawingDocumentObject Then
	oUserParams = ThisDoc.Document.Parameters.UserParameters
Else
	oUserParams = ThisDoc.Document.ComponentDefinition.Parameters.UserParameters
End If

dValue = 99
Try
	Parameter( "Foo") = dValue
Catch
	oParam = oUserParams.AddByValue("Foo", dValue, UnitsTypeEnum.kDefaultDisplayLengthUnits)
End Try

 

If you are working with assembly occurrences, then something like this will work

 

Dim oOcc As ComponentOccurrence = Component.InventorComponent("MyPart")
oUserParams = oOcc.Definition.Document.ComponentDefinition.Parameters.UserParameters

dValue = 99
Try
	Parameter(oOcc.Name, "Foo") = dValue
Catch
	oParam = oUserParams.AddByValue("Foo", dValue, UnitsTypeEnum.kDefaultDisplayLengthUnits)
End Try