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 can I obtain a real from a ValueInput that was created from a string?

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
j.g.doggett
238 Views, 2 Replies

How can I obtain a real from a ValueInput that was created from a string?

In "ValueInput expression namespace" 

BrianEkins says: "The API is just taking the string provided by the ValueInput object and passing into the internal function that will be creating the parameter.  It's at that time the string is being evaluated and used."

 

So how do I call this evaluation function from the API? I want to take a ValueInput containing say "5 in" and do maths with it as a cm length in my python code.

2 REPLIES 2
Message 2 of 3
JeromeBriot
in reply to: j.g.doggett
Message 3 of 3
j.g.doggett
in reply to: JeromeBriot

Thanks! The following is what I was looking for:

    app = adsk.core.Application.get()

    unitsMgr = app.activeProduct.unitsManager

    value_in_cm = unitsMgr.evaluateExpression("2 mm * sin(45)", unitsMgr.defaultLengthUnits)


I had gone down the ValueInput rabbit hole because initially I had expected that the real value would be updated to reflect the string value when it was set. And wasn't finding any leads in the documentation to where I should be looking ( app.activeProduct.unitsManager.evaluateExpression ).

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