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

Parameter values returned do not match the units

Julie_7
Advocate

Parameter values returned do not match the units

Julie_7
Advocate
Advocate

I have my design/document units set to mm.

There is a parameter defined which has the name of another parameter as its expression and its value is 50mm.

 

When using the API, this is what the parameter looks like.

Julie_7_0-1682885128941.png

 

You can see that the unit is mm as it should be, but the value is 5.0 instead of 50.00 which is shown in the value field in the parameters dialog.

 

While troubleshooting I referenced the API documentation for the Parameter Object https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-55297469-5aa5-4dd7-90ba-27483db7151a

and it has

 

Julie_7_1-1682885335274.png

I have questions about this:

  1. why is the value not in the units specified?
  2. why is the value not in the units specified for the document?
  3. what is database units referring to, and why is it used?
  4. why is value modifiable?    It is not modifiable in the UI, and modifying it can make it inconsistent with the expression.

 

0 Likes
Reply
Accepted solutions (1)
435 Views
4 Replies
Replies (4)

Julie_7
Advocate
Advocate

I did find the answer by starting at the beginning and find the information at the bottom of the Basic Concepts page.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-D93DF10F-4209-4073-A2A0-4FA8788C8709

 

          "Real values are always interpreted as Fusion 360’s database units; lengths are always centimeters and angles are always radians. "

 

I don't understand why it works this way, but now I can use it correctly. The first parameter values that I had retrieved had been unitless and matched what I saw in the UI so I made an assumption that was wrong.

 

 

1 Like

kandennti
Mentor
Mentor

Hi @Julie_7 .

 

I believe the UnitsManager object is provided to solve the length units problem.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-9c2d17c1-70c6-4c2d-ae9e-c6f6f283b1a9 

 

 

# Fusion360API Python script

import traceback
import adsk.core as core
import adsk.fusion as fusion

def run(context):
    ui: core.UserInterface = None
    try:
        app: core.Application = core.Application.get()
        ui = app.userInterface
        des: fusion.Design = app.activeProduct

        parameter = des.userParameters[0]

        unitsMgr: core.UnitsManager = app.activeProduct.unitsManager
        msgLst = [
            '******',
            f'parameter.value : \t{parameter.value}',
            f'parameter.unit : \t{parameter.unit}',
            '-----',
            f'formatInternalValue : \t{unitsMgr.formatInternalValue(parameter.value)}',
            'convert : \t\t{}'.format(
                unitsMgr.convert(
                    parameter.value,
                    unitsMgr.internalUnits,
                    unitsMgr.defaultLengthUnits
                )
            ),
        ]

        app.log('\n'.join(msgLst))

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

 

Here is an example of one of the results.

 

 ******
parameter.value : 	0.1
parameter.unit : 	mm
-----
formatInternalValue : 	1.00 mm
convert : 		1.0

 

I think it would be more difficult to have the internal values handled be affected by the units.

 

I know it is common practice to use radians for angles, but I am not sure why you chose "cm" as the internal length unit.

 

 

0 Likes

BrianEkins
Mentor
Mentor
Accepted solution

It's simpler to write a program when the units are consistent. This is also how Fusion works internally. The API units are the same as those used internally in Fusion. You can write all your code knowing that distances are always centimeters and angles are radians. The only time you need to do any conversions is when you are getting input from the user and displaying results. Still, even then, the various command inputs handle this conversion automatically for you.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
1 Like

Julie_7
Advocate
Advocate
I understand, but the choice of centimeters still seems strange to me. I've never met a machinist who works in centimeters.
0 Likes