Fusion 360 API Parameter Value does not match Expression

Fusion 360 API Parameter Value does not match Expression

savaric
Observer Observer
313 Views
3 Replies
Message 1 of 4

Fusion 360 API Parameter Value does not match Expression

savaric
Observer
Observer

Apologies if this has been answered, I've just spent 2 hours trying to figure this out and I can't explain it.

I'm pulling parameters using Python script and when I display the parameter value for an expression of 1/8" it shows me 0.3175.  Seeing this in several parameter values I've spot checked.

Code Snippet:

design = adsk.fusion.Design.cast(app.activeProduct)
for parm in design.allParameters:
  if parm.name == "d700":
    app.log(f'debug value: parm.name: {parm.name} value: {parm.value}, str: {str(parm.value)}')
fracVal = 1/8
app.log(f'fracVal = 1/8: {fracVal}')
floatVal = float(1/8)
app.log(f'floatVal = float(1/8): {floatVal}')
d = 1.0/8.0
app.log(f'd = 1.0/8.0: {d}')
 
Result:
 debug value: parm.name: d700 value: 0.3175, str: 0.3175
 fracVal = 1/8: 0.125
 floatVal = float(1/8): 0.125
 d = 1.0/8.0: 0.125

 

A lot of noise online about floating point precision, which is why I tested the 3 methods to generate a float value.

 

I have another UserParameter with an expression of 5 1/4", but the value prints as 13.335.

 

What am I missing?

 

Thanks in advance!

0 Likes
Accepted solutions (1)
314 Views
3 Replies
Replies (3)
Message 2 of 4

BrianEkins
Mentor
Mentor

The value property of the Parameter object always uses Fusion's internal units, which are centimeters for length.

1/8" = 0.3175 cm. 

Most of the API works in internal units. The units the user sets for the document are only used when getting or displaying values to the user. For example, you can use the UnitsManager object to convert 0.3175 to a string that uses the current document units and formats it using the user's preferences.

 

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 3 of 4

BrianEkins
Mentor
Mentor
Accepted solution

I forgot to include a link to the documentation that discusses units in the API.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-A81B295F-984A-4039-B1CF-B449BEE893D7

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 4 of 4

savaric
Observer
Observer

Thanks so much Brian for the quick response!  This was driving me nuts.  Really appreciate the guidance.

Harry

0 Likes