simple-expression

Post Reply
User avatar
gabrielp
Advanced member
Posts: 577
Joined: Fri Aug 08, 2014 4:31 pm
Location: Boston
Contact:

simple-expression

Post 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
Chat: open-automation @ gitter
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
freddyp
Advanced member
Posts: 413
Joined: Thu Feb 09, 2012 3:53 pm

Re: simple-expression

Post 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.
User avatar
gabrielp
Advanced member
Posts: 577
Joined: Fri Aug 08, 2014 4:31 pm
Location: Boston
Contact:

Re: simple-expression

Post 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.
Chat: open-automation @ gitter
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
Post Reply