Page 1 of 1

Send Switch Stat variables to JavaScript

Posted: Mon Mar 30, 2015 10:32 am
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.

Re: Send Switch Stat variables to JavaScript

Posted: Mon Mar 30, 2015 10:45 am
by _olq
Hello,

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

Image

Best regards,
Aleksander

Re: Send Switch Stat variables to JavaScript

Posted: Mon Mar 30, 2015 3:32 pm
by dkelly

Code: Select all

var width = job.getVariableAsNumber("[Stat.TrimboxWidth]"); 
var height = job.getVariableAsNumber("[Stat.TrimboxHeight]"); 

Re: Send Switch Stat variables to JavaScript

Posted: Mon Mar 30, 2015 4:10 pm
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.

Re: Send Switch Stat variables to JavaScript

Posted: Mon Mar 30, 2015 4:11 pm
by LasseThid
dkelly wrote:

Code: Select all

var width = job.getVariableAsNumber("[Stat.TrimboxWidth]"); 
var height = job.getVariableAsNumber("[Stat.TrimboxHeight]"); 
Thank you very much.

Re: Send Switch Stat variables to JavaScript

Posted: Mon Mar 30, 2015 10:34 pm
by andrea mahoney
You can use Round() in Switch Calculation variables.

Re: Send Switch Stat variables to JavaScript

Posted: Tue Mar 31, 2015 8:01 am
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.

Re: Send Switch Stat variables to JavaScript

Posted: Tue Mar 31, 2015 8:42 am
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;

Re: Send Switch Stat variables to JavaScript

Posted: Tue Mar 31, 2015 1:07 pm
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

Re: Send Switch Stat variables to JavaScript

Posted: Tue Mar 31, 2015 3:45 pm
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]);

Re: Send Switch Stat variables to JavaScript

Posted: Wed Apr 01, 2015 6:39 am
by LasseThid
Thanks for the explanation MoodyBro.

I will look into that next time I'm working on a script.