Page 1 of 1

simple-expression

Posted: Fri Jul 29, 2016 6:35 pm
by gabrielp
This is a script that routes jobs based on simple boolean or arithmetic expressions with binary operators.

https://github.com/open-automation/simple-expression

Just makes it easier and more contextual what can already be done within script expressions.

Image

Re: simple-expression

Posted: Mon Aug 01, 2016 9:14 am
by freddyp
Nice script, Gabriel.

However, not everybody has the Scripting Module and from experience I know that there is a little feature in Switch that is not well known and that is a viable alternative for the "Arithmetic" part of the script: the variable Switch - Calculation. In this movie https://www.youtube.com/watch?v=LBF_wc45cFI you find an introduction to this feature. It starts at 4:59.

Taking the "Number of pages % 4" example of the screenshot, that would be a condition with variables like this:
[Switch.Calculation:Expression="[Stats.NumberOfPages]%4"] - Equal to - 0
Equal to 1 would be the condition for being 3 pages short, etc.

Another case where Switch - Calculation is useful and that is not mentioned in the movie is that it allows you to cast a string to a number. Suppose a job starts with a job number before the first underscore and you have to determine if it is greater than a certain value. [Job.NameProper:Before="_"] will give you the string operators in the condition (Equal to, Contains, Starts with, etc.), but not "Greater than, Smaller than, etc. Putting [Job.NameProper:Before="_"] inside a Switch - Calculation solves that.

Re: simple-expression

Posted: Mon Aug 01, 2016 7:00 pm
by gabrielp
freddyp wrote: Taking the "Number of pages % 4" example of the screenshot, that would be a condition with variables like this:
[Switch.Calculation:Expression="[Stats.NumberOfPages]%4"] - Equal to - 0
Equal to 1 would be the condition for being 3 pages short, etc.
Did not think that would accept a modulus operator but I suppose it makes sense. Very good to know!
freddyp wrote:Another case where Switch - Calculation is useful and that is not mentioned in the movie is that it allows you to cast a string to a number.
I knew about this one, and it is very helpful.

I still have some useful functionality I plan on adding to this script, so it will be more valuable soon.