Send Switch Stat variables to JavaScript
Send Switch Stat variables to JavaScript
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.
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 2017, Enfocus PitStop Server 13u2, HP SmartStream 12 & Kodak Prinergy 7.5 with Rules Based Automation
MAN Roland R705 & R708, KBA Rapida 205, HP Indigo 7600, 7800 & 10000, Inca OnsetX2, Durst P10 among other things
MAN Roland R705 & R708, KBA Rapida 205, HP Indigo 7600, 7800 & 10000, Inca OnsetX2, Durst P10 among other things
Re: Send Switch Stat variables to JavaScript
Hello,
You don't need necessarily use Javascript.
You may use the built-in functions "Calculation"

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

Best regards,
Aleksander
Aleksander
-
- TOP CONTRIBUTOR
- Posts: 628
- Joined: Mon Nov 29, 2010 8:45 pm
- Location: Alpharetta GA USA
- Contact:
Re: Send Switch Stat variables to JavaScript
Code: Select all
var width = job.getVariableAsNumber("[Stat.TrimboxWidth]");
var height = job.getVariableAsNumber("[Stat.TrimboxHeight]");
Re: Send Switch Stat variables to JavaScript
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 ._olq wrote:Hello,
You don't need necessarily use Javascript.
You may use the built-in functions "Calculation"
Aleksander
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 2017, Enfocus PitStop Server 13u2, HP SmartStream 12 & Kodak Prinergy 7.5 with Rules Based Automation
MAN Roland R705 & R708, KBA Rapida 205, HP Indigo 7600, 7800 & 10000, Inca OnsetX2, Durst P10 among other things
MAN Roland R705 & R708, KBA Rapida 205, HP Indigo 7600, 7800 & 10000, Inca OnsetX2, Durst P10 among other things
Re: Send Switch Stat variables to JavaScript
Thank you very much.dkelly wrote:Code: Select all
var width = job.getVariableAsNumber("[Stat.TrimboxWidth]"); var height = job.getVariableAsNumber("[Stat.TrimboxHeight]");
Enfocus Switch 2017, Enfocus PitStop Server 13u2, HP SmartStream 12 & Kodak Prinergy 7.5 with Rules Based Automation
MAN Roland R705 & R708, KBA Rapida 205, HP Indigo 7600, 7800 & 10000, Inca OnsetX2, Durst P10 among other things
MAN Roland R705 & R708, KBA Rapida 205, HP Indigo 7600, 7800 & 10000, Inca OnsetX2, Durst P10 among other things
- andrea mahoney
- Newbie
- Posts: 19
- Joined: Tue Jan 25, 2011 8:53 pm
Re: Send Switch Stat variables to JavaScript
You can use Round() in Switch Calculation variables.
Re: Send Switch Stat variables to JavaScript
Thanks Andrea.
That's may make life a bit easier for me.
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.
That's may make life a bit easier for me.

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 2017, Enfocus PitStop Server 13u2, HP SmartStream 12 & Kodak Prinergy 7.5 with Rules Based Automation
MAN Roland R705 & R708, KBA Rapida 205, HP Indigo 7600, 7800 & 10000, Inca OnsetX2, Durst P10 among other things
MAN Roland R705 & R708, KBA Rapida 205, HP Indigo 7600, 7800 & 10000, Inca OnsetX2, Durst P10 among other things
Re: Send Switch Stat variables to JavaScript
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
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
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 2017, Enfocus PitStop Server 13u2, HP SmartStream 12 & Kodak Prinergy 7.5 with Rules Based Automation
MAN Roland R705 & R708, KBA Rapida 205, HP Indigo 7600, 7800 & 10000, Inca OnsetX2, Durst P10 among other things
MAN Roland R705 & R708, KBA Rapida 205, HP Indigo 7600, 7800 & 10000, Inca OnsetX2, Durst P10 among other things
Re: Send Switch Stat variables to JavaScript
The "Log" are just the messages in Switch 
You are able to write into these messages with "job.log":
The number "1" ist the message-type, so you are able to write Error-, Warning- oder just normal Info-Messages.

You are able to write into these messages with "job.log":
Code: Select all
job.log(1,"Hello world!");
You can also write some variable-informations into your "log":1 | Info (black)
2 | Warning (yellow)
3 | Error (red)
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
Thanks for the explanation MoodyBro.
I will look into that next time I'm working on a script.
I will look into that next time I'm working on a script.
Enfocus Switch 2017, Enfocus PitStop Server 13u2, HP SmartStream 12 & Kodak Prinergy 7.5 with Rules Based Automation
MAN Roland R705 & R708, KBA Rapida 205, HP Indigo 7600, 7800 & 10000, Inca OnsetX2, Durst P10 among other things
MAN Roland R705 & R708, KBA Rapida 205, HP Indigo 7600, 7800 & 10000, Inca OnsetX2, Durst P10 among other things