Hello, I want to use Script Expression but I have no knowledge about Java,
I think what I want is pretty simple.
if pages in pdf are odd than ....
else if pages in pdf are even than....
Can somebody help me out with this simple task?
Thank you very much.
Script expression - If - Else
-
- Newbie
- Posts: 19
- Joined: Mon Jun 01, 2015 8:05 am
- Location: Switzerland
Re: Script expression - If - Else
Code: Select all
var theVar = job.getVariableAsNumber("[Stats.NumberOfPages]");
if (theVar % 2 == 0 ) {
s.log(3, "Even!");
} else {
s.log(3, "Odd!");
}
%2 checks if theVar is dividable by 2, if so it's even, else odd

Part of my playground:
- HP Indigo 10k, HP Indigo 7600's (full options), Highcon Euclid III, Zünd S3
- HP Production Pro 6.0.1, HP Production Center 2.5.1 beta, Apogee 9.1, Enfocus Switch 13u1 & PitStop Server 13u2.
Chat: open-automation @ gitter
- HP Indigo 10k, HP Indigo 7600's (full options), Highcon Euclid III, Zünd S3
- HP Production Pro 6.0.1, HP Production Center 2.5.1 beta, Apogee 9.1, Enfocus Switch 13u1 & PitStop Server 13u2.
Chat: open-automation @ gitter
Re: Script expression - If - Else
You can solve this without scripting too.
I guess you want to sort even or odd pages from a PDF and do different things with them.
If you first split the PDF in Switch and UnGroup the folder the pages end up in you have files with a suffix of the page numbers.
On the connection out of the folder you have a condition [Job.NameProper:After="_"] that Matches ^\d*[13579]$
For even values you change to ^\d*[02468]$
I guess you want to sort even or odd pages from a PDF and do different things with them.
If you first split the PDF in Switch and UnGroup the folder the pages end up in you have files with a suffix of the page numbers.
On the connection out of the folder you have a condition [Job.NameProper:After="_"] that Matches ^\d*[13579]$
For even values you change to ^\d*[02468]$
-
- Newbie
- Posts: 19
- Joined: Mon Jun 01, 2015 8:05 am
- Location: Switzerland
Re: Script expression - If - Else
Hi Jan, that solution was not possible in this case, Im using a third party configurator and the only way is here to work with script expressions.jan_suhr wrote:You can solve this without scripting too.
I guess you want to sort even or odd pages from a PDF and do different things with them.
If you first split the PDF in Switch and UnGroup the folder the pages end up in you have files with a suffix of the page numbers.
On the connection out of the folder you have a condition [Job.NameProper:After="_"] that Matches ^\d*[13579]$
For even values you change to ^\d*[02468]$
But thank you for your help.

-
- Newbie
- Posts: 19
- Joined: Mon Jun 01, 2015 8:05 am
- Location: Switzerland
Re: Script expression - If - Else
sander wrote:Something like this?Code: Select all
var theVar = job.getVariableAsNumber("[Stats.NumberOfPages]"); if (theVar % 2 == 0 ) { s.log(3, "Even!"); } else { s.log(3, "Odd!"); }
%2 checks if theVar is dividable by 2, if so it's even, else odd
Hi sander, exactly like that

Do you personaly write these expressions directly in the script expression window or is there a better more elegant way to write scripts like that?
Re: Script expression - If - Else
Most of the script expressions only hold a few lines of code and I write these from within the script expression window itself. In practice: copy, paste and adjust 
If the script is bigger then I use Switch Scripter, however I barely use these as a script expression.

If the script is bigger then I use Switch Scripter, however I barely use these as a script expression.
Part of my playground:
- HP Indigo 10k, HP Indigo 7600's (full options), Highcon Euclid III, Zünd S3
- HP Production Pro 6.0.1, HP Production Center 2.5.1 beta, Apogee 9.1, Enfocus Switch 13u1 & PitStop Server 13u2.
Chat: open-automation @ gitter
- HP Indigo 10k, HP Indigo 7600's (full options), Highcon Euclid III, Zünd S3
- HP Production Pro 6.0.1, HP Production Center 2.5.1 beta, Apogee 9.1, Enfocus Switch 13u1 & PitStop Server 13u2.
Chat: open-automation @ gitter