Script expression - If - Else

Post Reply
Chrissigge
Member
Posts: 20
Joined: Mon Jun 01, 2015 8:05 am
Location: Switzerland

Script expression - If - Else

Post 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.
sander
Advanced member
Posts: 274
Joined: Wed Oct 01, 2014 8:58 am
Location: The Netherlands

Re: Script expression - If - Else

Post 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 ;)
jan_suhr
Advanced member
Posts: 586
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Re: Script expression - If - Else

Post 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 7295 times
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps
Chrissigge
Member
Posts: 20
Joined: Mon Jun 01, 2015 8:05 am
Location: Switzerland

Re: Script expression - If - Else

Post 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. :)
Chrissigge
Member
Posts: 20
Joined: Mon Jun 01, 2015 8:05 am
Location: Switzerland

Re: Script expression - If - Else

Post 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?
sander
Advanced member
Posts: 274
Joined: Wed Oct 01, 2014 8:58 am
Location: The Netherlands

Re: Script expression - If - Else

Post 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.
Post Reply