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: 

Convert value to fractional inch

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
thomasa88
192 Views, 2 Replies

Convert value to fractional inch

Hi, the following function can convert values between different units:

adsk.core.Application.get().activeProduct.fusionUnitsManager.convert(2.54, "cm", "inch")

 

That works well, but now I want to convert a value to a fractional inch, say 3.25" to 3 1/4". How can I do that?

2 REPLIES 2
Message 2 of 3
JeromeBriot
in reply to: thomasa88

Hello,

 

I don't know if something exists in the API, but in Python you can do this:

import fractions
val_dec = 3.25
val_frac = fractions.Fraction(val_dec)
print("{} {}".format(int(val_dec), val_frac % 1))
Message 3 of 3
BrianEkins
in reply to: JeromeBriot

I can confirm that there is nothing in the API to get fractions.  Thanks to @JeromeBriot for pointing out there is something in the Python library.  I wasn't aware of that.

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

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