Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

how does one control how unitless values are interpreted?

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
mojobility
505 Views, 4 Replies

how does one control how unitless values are interpreted?

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?

4 REPLIES 4
Message 2 of 5
ekinsb
in reply to: mojobility

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
Message 3 of 5
mojobility
in reply to: ekinsb

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.

Message 4 of 5
ekinsb
in reply to: mojobility

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
Message 5 of 5
mojobility
in reply to: ekinsb

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.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report