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

j.g.doggett
Explorer

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

j.g.doggett
Explorer
Explorer

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.

0 Likes
Reply
Accepted solutions (1)
412 Views
2 Replies
Replies (2)

JeromeBriot
Mentor
Mentor
Accepted solution
0 Likes

j.g.doggett
Explorer
Explorer

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 ).

0 Likes