ValueInput expression namespace

ValueInput expression namespace

william-c-anderson
Advocate Advocate
1,245 Views
5 Replies
Message 1 of 6

ValueInput expression namespace

william-c-anderson
Advocate
Advocate

The section on units ( Understanding Units in Fusion 360) asserts that the ValueInput object can evaluate expressions, to wit:

 

The ValueInput object serves as a way to pass in either a string or a real value through a single argument. If you pass in a string, that string is used as the equation of the parameter that's created. This means it can include references to other parameters, functions, etc. (emphasis mine) If you pass in a real value, an equation is computed by Fusion 360 and displayed in the parameters dialog.

 

In what context / namespace is this expression parsed and evaluated? It is mentioned that functions can be referenced. What functions? Anything in the Python math module? What other parameters are in the namespace? The ValueInput reference manual page does not elucidate the above statement, only that 'createByString' can evaluate elementary expressions.

 

0 Likes
Accepted solutions (1)
1,246 Views
5 Replies
Replies (5)
Message 2 of 6

BrianEkins
Mentor
Mentor

To clarify, the ValueInput doesn't do any evaluation of expressions.  It's just an object that serves as a wrapper for either a string or a real number.  Where the evaluation happens is when you use it as input to create something.  For example, when you provide the ValueInput to define the length of an extrude feature, a parameter is created and the feature is dependent on that parameter.  Assuming the ValueInput contains a string, that string is used as the expression of the parameter.  It's when the parameter is created when the string is evaluated.

 

As far as functions, it's referring to functions you can use in the expression of a parameter.  For example, if I have a parameter named "Length" that has a length value and another named "Angle" that has an angle value, I can create a new parameter where the expression is "Length * cos(Angle)" where I use the built-in cosine function.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes
Message 3 of 6

william-c-anderson
Advocate
Advocate

So, any function that I can use in a User Parameter expression, and the value of any User Parameter, are in the namespace of the ValueInput wrapper, which seems to be the same namespace (per my experimentation) as for 

unitsMgr.evaluateExpression().
 
Is the set of so-called "built-in" functions documented anywhere? It's not mentioned in the UserParameter documentation AFAIK. I've also noticed that some obvious functions/values seem to be missing (e.g. pi).
0 Likes
Message 5 of 6

BrianEkins
Mentor
Mentor

Here's the documentation for Fusion.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-76272551-3275-46C4-AE4D-10D58B408C20

 

Rather than say in the "namespace of the ValueInput", I would say it's in the namespace of the design and the parameters.  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.  You can create a ValueInput with garbage and the API won't care.  It's when you use it to create something that the string is evaluated.

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

william-c-anderson
Advocate
Advocate
Accepted solution

Thanks! That document is really helpful.

 

0 Likes