Copy link to clipboard
Copied
Hi everyone,
I have just joined this Adobe Community Forum on the advice of someone I know who has told me about Actions and Scripts. They said this place is very helpful and a wealth of knowledge and I thought this would be the perfect place to get help with something I need streamlined.
I print on boxes in a pretty much non-for-profit that gives an alternative to plastic ecommerce cartons and such with recycled cartons pritned with environmentally sustainable and vegetable inks. When we print on these boxes Artists are required to mock them up to size on screen first then output to print once approved.
Below is a standard carton flat mockup ready for artwork to be applied. Right now the artists draw these boxes up manually. We're given sizing and scoring positions - one in the length and one in the width. In this case It's 30 150 300 150 297 in the Length direction and 75 200 75 in the width direction.
Drawing this up manually can take time and be tedious. I was wondering if there is a type of action or script that I could use that we could just copy and paste these two sets of numbers in and it generates our flat carton mockup as seen below. For everything we do these numbers are always almost differernt.
Thanks for any help!
Copy link to clipboard
Copied
// var w = [30, 150, 300, 150, 297];
// var h = [75, 200, 75];
var ws = prompt("Enter any number of widths separated by commas", "30, 150, 300, 150, 297", "Widths");
var hs = prompt("Enter any number of hights separated by commas", "75, 200, 75", "Hights");
var w = ws.split(",");
for (var i = 0; i < w.length; i++){w[i] = Number(w[i]);}
var h = hs.split(",");
for (var i = 0; i < h.length; i++){h[i] = Number(h[i]);}
var d = app.activeDocument.artboards[0].artboardRect;
var w1 = 0;
for (var i in w){w1 += w[i];}
var h1 = 0;
for (var i in h){h1 += h[i];}
var h2 = d[3]/2+h1/2;
for (var j = 0; j < h.length; j++) {
var w2 = d[2]/2-w1/2;
for (var i = 0; i < w.length; i++) {
var rect0 = app.activeDocument.pathItems.rectangle(h2, w2, w[i], h[j]);
rect0.name = "rect " + (j + 1) + ", " + (i + 1);
w2 = w2 + w[i];
}
h2 = h2 - h[j];
}
// delete top and bottom left
app.activeDocument.pathItems["rect 1, 1"].remove();
app.activeDocument.pathItems["rect " + h.length + ", 1"].remove();
Copy link to clipboard
Copied
Thanks, I really appreciate this. I just tried it and it generates but is there anyway I can have the units generate in millimetres instead of pixels?
Copy link to clipboard
Copied
// var ws = "30, 150, 300, 150, 297";
// var hs = "75, 200, 75";
var f = 2.83465;
var ws = prompt("Enter any number of widths (in mm) separated by commas", "30, 150, 300, 150, 297", "Widths");
var hs = prompt("Enter any number of hights (in mm) separated by commas", "75, 200, 75", "Hights");
var w = ws.split(",");
for (var i = 0; i < w.length; i++){w[i] = Number(w[i])*f;}
var h = hs.split(",");
for (var i = 0; i < h.length; i++){h[i] = Number(h[i])*f;}
var d = app.activeDocument.artboards[0].artboardRect;
var w1 = 0;
for (var i in w){w1 += w[i];}
var h1 = 0;
for (var i in h){h1 += h[i];}
var h2 = d[3]/2+h1/2;
for (var j = 0; j < h.length; j++) {
var w2 = d[2]/2-w1/2;
for (var i = 0; i < w.length; i++) {
var rect0 = app.activeDocument.pathItems.rectangle(h2, w2, w[i], h[j]);
rect0.name = "rect " + (j + 1) + ", " + (i + 1);
w2 = w2 + w[i];
}
h2 = h2 - h[j];
}
// delete top and bottom left
app.activeDocument.pathItems["rect 1, 1"].remove();
app.activeDocument.pathItems["rect " + h.length + ", 1"].remove();
Copy link to clipboard
Copied
I just tried it and it works great! Thank you so much! Great job!
Copy link to clipboard
Copied
Hi,
Just a follow up to this awesome solution. Is there any way or is it possible to have this Script work without having commas in between the values? It's just quicker as our Admin software generates them as 30 150 300 150 297 and 75 200 75 with no commas for example and would be easier for the guys to straight copy and paste as they do many of these a day and adding commas in between seems to be an annoyance to them when they just want to copy and paste. Trivial I know but Artists are a very particular type of people 🙂
Copy link to clipboard
Copied
Untested.
Try swapping the first few lines of code like this:
// var ws = "30 150 300 150 297";
// var hs = "75 200 75";
var f = 2.83465;
var ws = prompt("Enter any number of widths (in mm) separated by space", "30 150 300 150 297", "Widths");
var hs = prompt("Enter any number of hights (in mm) separated by space", "75 200 75", "Hights");
var w = ws.split(" ");
Copy link to clipboard
Copied
Here it is in full:
var f = 2.83465;
var ws = prompt("Enter any number of widths (in mm) separated by spaces", "30 150 300 150 297", "Widths");
var hs = prompt("Enter any number of hights (in mm) separated by spaces", "75 200 75", "Hights");
var w = ws.split(" ");
for (var i = 0; i < w.length; i++){w[i] = Number(w[i])*f;}
var h = hs.split(" ");
for (var i = 0; i < h.length; i++){h[i] = Number(h[i])*f;}
var d = app.activeDocument.artboards[0].artboardRect;
var w1 = 0;
for (var i in w){w1 += w[i];}
var h1 = 0;
for (var i in h){h1 += h[i];}
var h2 = d[3]/2+h1/2;
for (var j = 0; j < h.length; j++) {
var w2 = d[2]/2-w1/2;
for (var i = 0; i < w.length; i++) {
var rect0 = app.activeDocument.pathItems.rectangle(h2, w2, w[i], h[j]);
rect0.name = "rect " + (j + 1) + ", " + (i + 1);
w2 = w2 + w[i];
}
h2 = h2 - h[j];
}
// delete top and bottom left
app.activeDocument.pathItems["rect 1, 1"].remove();
app.activeDocument.pathItems["rect " + h.length + ", 1"].remove();