Extending Expressions for User Defined Parameters

Extending Expressions for User Defined Parameters

KennethOfLeesburg
Contributor Contributor
857 Views
3 Replies
Message 1 of 4

Extending Expressions for User Defined Parameters

KennethOfLeesburg
Contributor
Contributor

I wanted to use the API to create a function (or subroutine) that could be used when defining user parameters.

 

There are two cases:  1) the function consists only of expressions that can be represented with the existing expression language and 2) the function computation requires some control flow.

 

The first case could be done completely within your existing expression evaluation engine (i.e., it's a subroutine).  If a user invokes a user defined function then you do macro expansion and proceed in the normal fashion.  You might require some special syntactic convention for user defined functions (if that helps). But this could hide a great deal of clutter and more importantly facilitate "code-reuse" for the expressions used in user parameters.  I have an example where I'm doing non-isomorphic scaling.  Each time I do this it only require 3 or 4 sub-expressions, but I do this a dozen (or two dozen) times.  If I write it all out manually the clutter is confusing (especially to someone maintaining my design), but worse, I spend a lot of time tracking down silly, but subtle, mistakes.

 

The second case requires you to call my code.  Which is fine by me, but it will prevent you from doing symbolic optimizations (if that is in the roadmap) and it could livelock or deadlock if my code does something unexpected.  (And there are security implications).

 

I've read a bunch in the API document and can't find anyway to do anything like this.  Can someone confirm that this is correct, it's not just that I'm overlooking something.  I would not argue that this is more urgent than other things, but I had a need.  Is it on the roadmap?

Accepted solutions (1)
858 Views
3 Replies
Replies (3)
Message 2 of 4

BrianEkins
Mentor
Mentor
Accepted solution

I don't believe this is currently possible.  There currently isn't any way to extend a Fusion expression beyond a simple equation.  And there also isn't any way to be notified when a parameter value changes so you could react to that in some way.

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

quality5B59E
Contributor
Contributor

A hack might be to put your special expression in the comments, perhaps.  Then you can parse it, execute it and update the value on your own?

0 Likes
Message 4 of 4

KennethOfLeesburg
Contributor
Contributor

I had started to code this approach.  Put the formula in the comment, parse it, and update the value.

 

I hadn't gotten very far, but I've had a loss of confidence around the issue of where my code should "hook in".  An event for parameter updates would be nice, but as BrianEkins points out there isn't such an event.  And to do it "right" you would need an event (on which you could register a handler) for each user defined parameter; I don't want to recomput every time any parameter is updated, only when parameters that are arguments to the computation of "my" parameter are changed.  I don't know how expensive the associated asynchronous context switch is (in this case), but an event for every user defined parameter could be clunky slow.

 

So is there any way for me to add a "recompute" button on the Parameters window?

 

It appears that you can click a "recompute" button on one of the normal toolbar panels without closing the parameters window.  Is there a know reason why this wouldn't work?

 

Also the store had an add in for loading user parameters from an excel spreadsheet.  How did they handle the analogous issues?

 

0 Likes