I would recommend a couple of small changes to @Jorge_Jaramillo great post.
if not distParam:
# parameter doesn't exists -> lets creat it
distVal = adsk.core.ValueInput.createByString(valInp.expression)
distParam = design.userParameters.add(DISTANCE_PARAMETER, distVal, design.unitsManager.defaultLengthUnits, '')
else:
# paremeter already exists -> lest update its expression attribute
distParam.expression = valInp.expression
When creating a new parameter, it is usually best to use the defaultLengthUnit property of the UnitsManager. This returns whatever the user has set as their length units for the design. For example, if they've chosen inches it will return "inch," and if they've chosen millimeters, it will return "mm", etc.
I also changed it to use the expression property of the ValueInput instead of value. The expression property returns the string the user has entered in the ValueInput. The value property converts that string to a number that is always in centimeters, if the value represents a length. The big advantage of using the expression is you keep any equations the user has entered. For example, they could enter "d1/2" into the ValueInput. The expression property will return "d1/2" and this expression is then assigned to the parameter which knows how to evaluate the string to get the correct value.
---------------------------------------------------------------
Brian EkinsInventor and Fusion 360 API Expert
Website/Blog:
https://EkinsSolutions.com