In a flow I needed to calculate how many times a step and repeat imposition could be repeated on 965 mm.
I could not get my math to work with Switch calculations, so I decided to write a script to calculate and return a new private data key with the number I needed.
But it took me way to long because I think I messed up declaring my variables as numbers/floats.
The code below works, but is probably not the best code.
What is the best way to read a private data key and have the script intepret it as a number (which can contain decimals)?
Code: Select all
async function jobArrived(s: Switch, flowElement: FlowElement, job: Job) {
let ImposeRoll: string = await job.getPrivateData("ImposeRoll");
let BleedRoll: string = await job.getPrivateData("BleedRoll");
let Width: string = await job.getPrivateData("Width");
let ImposeRollPrintOnCutterFloor: number = 0
let ImposeRollPrintOnCutter: number = 0
let MarksRollPrint: number = 0
ImposeRollPrintOnCutterFloor = await Math.floor((965 / (Number(ImposeRoll) * (Number(BleedRoll) + Number(Width)))));
ImposeRollPrintOnCutter = await ImposeRollPrintOnCutterFloor * Number(ImposeRoll);
MarksRollPrint = await Number(ImposeRollPrintOnCutter) - 1;
await job.setPrivateData("ImposeRollPrintOnCutter", ImposeRollPrintOnCutter);
await job.setPrivateData("MarksRollPrint", MarksRollPrint);
await job.log(LogLevel.Info, "ImposeRoll: " + ImposeRoll);
await job.log(LogLevel.Info, "BleedRoll: " + BleedRoll);
await job.log(LogLevel.Info, "Width: " + Width);
await job.log(LogLevel.Info, "ImposeRollPrintOnCutterFloor: " + ImposeRollPrintOnCutterFloor);
await job.log(LogLevel.Info, "ImposeRollPrintOnCutter: " + ImposeRollPrintOnCutter);
await job.log(LogLevel.Info, "MarksRollPrint: " + MarksRollPrint);
await job.sendToSingle();
}