Page 1 of 1

Script expression - If - Else

Posted: Tue Jul 04, 2017 1:58 pm
by Chrissigge
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.

Re: Script expression - If - Else

Posted: Tue Jul 04, 2017 2:27 pm
by sander

Code: Select all

var theVar = job.getVariableAsNumber("[Stats.NumberOfPages]");
if (theVar % 2 == 0 ) {
	s.log(3, "Even!");
} else {
	s.log(3, "Odd!");
}
Something like this?

%2 checks if theVar is dividable by 2, if so it's even, else odd ;)

Re: Script expression - If - Else

Posted: Tue Jul 04, 2017 2:48 pm
by jan_suhr
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]$

Screenshot 2017-07-04 14.46.44.jpg
Screenshot 2017-07-04 14.46.44.jpg (133.52 KiB) Viewed 7333 times

Re: Script expression - If - Else

Posted: Thu Jul 06, 2017 1:11 pm
by Chrissigge
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]$

Screenshot 2017-07-04 14.46.44.jpg
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.
But thank you for your help. :)

Re: Script expression - If - Else

Posted: Thu Jul 06, 2017 1:14 pm
by Chrissigge
sander wrote:

Code: Select all

var theVar = job.getVariableAsNumber("[Stats.NumberOfPages]");
if (theVar % 2 == 0 ) {
	s.log(3, "Even!");
} else {
	s.log(3, "Odd!");
}
Something like this?

%2 checks if theVar is dividable by 2, if so it's even, else odd ;)

Hi sander, exactly like that :D . Thank you.
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

Posted: Thu Jul 06, 2017 1:30 pm
by sander
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 :P

If the script is bigger then I use Switch Scripter, however I barely use these as a script expression.