Send Switch Stat variables to JavaScript

Post Reply
LasseThid
Advanced member
Posts: 353
Joined: Tue Mar 03, 2015 2:30 pm
Location: Molndal, Sweden

Send Switch Stat variables to JavaScript

Post by LasseThid »

Is it possible to somehow use the Stat.TrimboxWidth and Stat.TrimboxHeight variables in a JavaScript for use in a calculation?
I need to somehow calculate the width and height of a pdf in millimeters without decimals and then send the result back to switch.
Enfocus Switch, Enfocus PitStop Server, Enfocus PDF Review, HP SmartStream& Kodak Prinergy with RBA
Offset 72x102, Offset Large Format, Digital Large Format and Digital print.
_olq
Member
Posts: 36
Joined: Fri Aug 23, 2013 10:21 am
Location: Poland

Re: Send Switch Stat variables to JavaScript

Post by _olq »

Hello,

You don't need necessarily use Javascript.
You may use the built-in functions "Calculation"

Image

Best regards,
Aleksander
Aleksander
dkelly
TOP CONTRIBUTOR
Posts: 658
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

Re: Send Switch Stat variables to JavaScript

Post by dkelly »

Code: Select all

var width = job.getVariableAsNumber("[Stat.TrimboxWidth]"); 
var height = job.getVariableAsNumber("[Stat.TrimboxHeight]"); 
LasseThid
Advanced member
Posts: 353
Joined: Tue Mar 03, 2015 2:30 pm
Location: Molndal, Sweden

Re: Send Switch Stat variables to JavaScript

Post by LasseThid »

_olq wrote:Hello,

You don't need necessarily use Javascript.
You may use the built-in functions "Calculation"

Aleksander
The problem with the Switch Calculation is that you get atleast one decimal and HP SmartStream Designer Imposition is not able to import an imposition containing a . in the file name, i.e. 90.0x55.0 is seen by SmartStream designer as 90 .

The way to get around it would be to divide the result by 10 with one decimal and then multiply by 10, but I'm not sure if that will do they job.

With JavaScript I can use .floor and get rid of the decimals in the calculation.
Last edited by LasseThid on Mon Mar 30, 2015 4:12 pm, edited 1 time in total.
Enfocus Switch, Enfocus PitStop Server, Enfocus PDF Review, HP SmartStream& Kodak Prinergy with RBA
Offset 72x102, Offset Large Format, Digital Large Format and Digital print.
LasseThid
Advanced member
Posts: 353
Joined: Tue Mar 03, 2015 2:30 pm
Location: Molndal, Sweden

Re: Send Switch Stat variables to JavaScript

Post by LasseThid »

dkelly wrote:

Code: Select all

var width = job.getVariableAsNumber("[Stat.TrimboxWidth]"); 
var height = job.getVariableAsNumber("[Stat.TrimboxHeight]"); 
Thank you very much.
Enfocus Switch, Enfocus PitStop Server, Enfocus PDF Review, HP SmartStream& Kodak Prinergy with RBA
Offset 72x102, Offset Large Format, Digital Large Format and Digital print.
User avatar
andrea mahoney
Newbie
Posts: 19
Joined: Tue Jan 25, 2011 8:53 pm

Re: Send Switch Stat variables to JavaScript

Post by andrea mahoney »

You can use Round() in Switch Calculation variables.
LasseThid
Advanced member
Posts: 353
Joined: Tue Mar 03, 2015 2:30 pm
Location: Molndal, Sweden

Re: Send Switch Stat variables to JavaScript

Post by LasseThid »

Thanks Andrea.
That's may make life a bit easier for me. :lol:

Update:
I can't figure out how to use Round() in my calculation.
[Switch.Calculation:Expression="Round([Stats.TrimBoxWidth]/72*25.4)"] results in the value 0 instead of the expected 90.
Enfocus Switch, Enfocus PitStop Server, Enfocus PDF Review, HP SmartStream& Kodak Prinergy with RBA
Offset 72x102, Offset Large Format, Digital Large Format and Digital print.
User avatar
MoodyBro
Newbie
Posts: 4
Joined: Mon Mar 30, 2015 3:27 pm

Re: Send Switch Stat variables to JavaScript

Post by MoodyBro »

Code: Select all

Round([Switch.Calculation:Expression="[Stats.TrimBoxWidth]/2.83464"])

You could also use a script-expression so you can log your parameters:

Code: Select all

var width = Math.round(job.getVariableAsNumber("[Stats.TrimBoxWidth]")/2.83464);
job.log(2,"Width: %1", width);

width;
LasseThid
Advanced member
Posts: 353
Joined: Tue Mar 03, 2015 2:30 pm
Location: Molndal, Sweden

Re: Send Switch Stat variables to JavaScript

Post by LasseThid »

Thanks to everyone for helping me out.

Script is done now and working as expected.

@MoodyBro:
As I'm just starting to learn scripting I'm a bit curious about the log thing.
Can you expand on how it's working and how to use it, either here or in a PM?

Thanks
Lasse
Enfocus Switch, Enfocus PitStop Server, Enfocus PDF Review, HP SmartStream& Kodak Prinergy with RBA
Offset 72x102, Offset Large Format, Digital Large Format and Digital print.
User avatar
MoodyBro
Newbie
Posts: 4
Joined: Mon Mar 30, 2015 3:27 pm

Re: Send Switch Stat variables to JavaScript

Post by MoodyBro »

The "Log" are just the messages in Switch ;)
You are able to write into these messages with "job.log":

Code: Select all

job.log(1,"Hello world!");
The number "1" ist the message-type, so you are able to write Error-, Warning- oder just normal Info-Messages.
1 | Info (black)
2 | Warning (yellow)
3 | Error (red)
You can also write some variable-informations into your "log":

Code: Select all

// myFile = "flyer_2015.pdf";
job.log(3,"The process for file %1 doesn't work!", myFile);
// This will write a red text into your log: "The process for file flyer_2015.pdf doesn't work!"


// you can also use more than just one variable
job.log(2,"FirstVariable = %11, SecondVariable = %12", [firstVar, secondVar]);
LasseThid
Advanced member
Posts: 353
Joined: Tue Mar 03, 2015 2:30 pm
Location: Molndal, Sweden

Re: Send Switch Stat variables to JavaScript

Post by LasseThid »

Thanks for the explanation MoodyBro.

I will look into that next time I'm working on a script.
Enfocus Switch, Enfocus PitStop Server, Enfocus PDF Review, HP SmartStream& Kodak Prinergy with RBA
Offset 72x102, Offset Large Format, Digital Large Format and Digital print.
Post Reply