Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
1

Action or Script to Create sets of Boxes Automatically

Explorer ,
Feb 13, 2021 Feb 13, 2021

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!

 

 

Screen Shot 2021-02-14 at 2.25.27 pm.pngexpand image

 

 

TOPICS
Print and publish , Scripting , SDK , Tools
2.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 3 Correct answers

Guide , Feb 14, 2021 Feb 14, 2021
// 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].ar
...
Translate
Community Expert , Feb 20, 2021 Feb 20, 2021

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(" ");

 

Translate
Guide , Feb 20, 2021 Feb 20, 2021

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];}
...
Translate
Adobe
Guide ,
Feb 14, 2021 Feb 14, 2021
// 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();

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 14, 2021 Feb 14, 2021

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Feb 14, 2021 Feb 14, 2021
// 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();

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 14, 2021 Feb 14, 2021

I just tried it and it works great! Thank you so much! Great job!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 20, 2021 Feb 20, 2021

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 🙂

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 20, 2021 Feb 20, 2021

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(" ");

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Feb 20, 2021 Feb 20, 2021

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();
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 09, 2022 Aug 09, 2022

Thank you for the script dude you are amazing,

Is it possible to modify it that can match below photo

So I only have to input 3 dimensions (L,W,H)

 

RSC.jpgexpand image

Thank you in advance

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Aug 09, 2022 Aug 09, 2022
var f = 2.83465;
var IP1 = prompt("Enter L,W,H (in mm) separated by commas", "");
var IP2 = IP1.split(",");
var w = [IP2[0] * f, IP2[1] * f, IP2[0] * f, IP2[1] * f, 35 * f];
var h = [w[1] / 2, IP2[2] * f, w[1] / 2];
var d = app.activeDocument.artboards[0].artboardRect;
var w1 = ((w[0] + w[1]) * 2) + w[4];
var h1 = (h[0] * 2) + h[1];
var h2 = d[3] / 2 + h1 / 2;
for (var j = 0; j < 3; j++) {
    var w2 = d[2] / 2 - w1 / 2;
    for (var i = 0; i < 5; i++) {
        var rect = app.activeDocument.pathItems.rectangle(h2, w2, w[i], h[j]);
        rect.name = "rect " + (j + 1) + ", " + (i + 1);
        w2 = w2 + w[i];
    }
    h2 = h2 - h[j];
}
app.activeDocument.pathItems["rect 1, 5"].remove();
app.activeDocument.pathItems["rect 3, 5"].remove();
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 17, 2023 Apr 17, 2023
LATEST

Can you help me show dimensions above and on the left as shown in attached pictureUntitled-3.jpgexpand image

Thank you in advance !

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines