how does one control how unitless values are interpreted?

how does one control how unitless values are interpreted?

Anonymous
Not applicable
1,069 Views
4 Replies
Message 1 of 5

how does one control how unitless values are interpreted?

Anonymous
Not applicable

In the GUI I set Preferences/Default Units/Design to "in".  In the gui's browser under the root component is the item "Units:in"
I've also tried adding to my script
    app = adsk.core.Application.get()
    ui  = app.userInterface
    product = app.activeProduct
    design = adsk.fusion.Design.cast(product)
    design.fusionUnitsManager.distanceDisplayUnits = adsk.fusion.DistanceUnits.InchDistanceUnits

 

When I sketch in the GUI numbers get "in" labels automatically added and are interpreted as inches.


But when I use the method SketchCircles.addByCenterRadius(centerPoint, radius) with radius of type double, I get a circle sized as if radius was interpreted as centimeters.

The following also is interpreted in centimeters
    extrudeInput.setDistanceExtent(False, adsk.core.ValueInput.createByReal(1.0))

How do I change the way these unitless values are interpreted?

0 Likes
Accepted solutions (1)
1,070 Views
4 Replies
Replies (4)
Message 2 of 5

ekinsb
Alumni
Alumni
Accepted solution

The internal unit of Fusion and the API is centimeters.  API calls that return a number (vs a String) or take a number that represents a distance value will ALWAYS be centimeters.  Angles will ALWAYS be in radians.  The setting that you pointed out controls how the user interface works with values but does not change how values are used internally.  At first this might seem like a problem but as you use it it actually makes things easier because you can write code independent of any user settings.  The only time you have to do anything about units is when you get input from or display results to the user.  And the UnitsManager class provides utilities to help with both of these cases. 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 3 of 5

Anonymous
Not applicable

I prefer the approach of design or document level properties that state what the units are as opposed to having a fixed internal unit.  Then when one looks at data through a debugger one sees values in the design's units without need to convert.

0 Likes
Message 4 of 5

ekinsb
Alumni
Alumni

That can make debugging easier but usually ends up complicating other parts of your program to be able to work with different units.  Since the user can change the units, your program should be able to correctly handle whatever the user has input.  Ideally it should also handle cases where they override the current units in what they type ("3 mm") or even use equations or reference a parameter ("3 in + 5 cm + Length").  And then when displaying results to the user you want to display them in whatever units they've chosen and using the number of decimal places they've specified in their preferences.  All of this is possible and even relatively easy using the UnitManager object.  Having consistent units in your program makes all of your code independent of user specified units except when getting or displaying values.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 5 of 5

Anonymous
Not applicable

When a script or program is to be part of an interactive session it can use the user interface methods to handle conversions.  In many of those cases the script does not care about units, it prompts the user for input and passes it through the API, letting the API convert it as needed.

 

But a script can also be the design itself.  There is no user to change the units, just the programmer who would prefer to work in the units of the problem space instead of being forced to work in centimeters and radians.

0 Likes