Skip to main content
Participant
September 16, 2021
Answered

Multiple artboards plugin

  • September 16, 2021
  • 2 replies
  • 904 views

Hey there Community,

maybe you have heard something about it, or maybe you can help me out with writing down a script. 

The script I am looking for should be able to create multiple different sized artboards at once.

 

Any help with this? 🙂

This topic has been closed for replies.
Correct answer femkeblanco

I did this in a rush.  See if it works for you. 

 

Open a new document before running the script.  Units are in points. 

 

var ws = [], hs = [], n;
var dialog1 = new Window("dialog");
    dialog1.add("statictext", undefined, "How many artboards?");
var input1 = dialog1.add("edittext", undefined, "n");
    input1.characters = 4;
    input1.active = true;
    input1.onChange = function () {n = Number(input1.text);};
var button1 = dialog1.add("button", undefined, "Next");
    button1.onClick = function () {
        var dialog2 = new Window("dialog");
        for (var i = 0; i < Math.min(n, 20); i++) {
            (function() {
                var group = dialog2.add("group");
                group.add("statictext", undefined, "#" + (i + 1));
                var w = group.add("edittext", undefined, "w");
                    w.characters = 4;
                    w.onChange = function () {ws.push(w.text);}
                group.add("statictext", undefined, "x");
                var h = group.add("edittext", undefined, "h");
                    h.characters = 4;
                    h.onChange = function () {hs.push(h.text);}
            } ());
        }
        var button2 = dialog2.add("button", undefined, "OK");
        dialog2.show();
        dialog1.close();
    };
dialog1.show();
var doc = app.activeDocument;
var AR = doc.artboards[0].artboardRect = [0, 0, ws[0], - hs[0]];   
for (var i = 1; i < n; i++) { 
    doc.artboards.add([AR[0], AR[3] - 10, ws[i], (AR[3] - 10 - hs[i])]);
    AR = doc.artboards[i].artboardRect;  
}

2 replies

femkeblanco
femkeblancoCorrect answer
Legend
September 18, 2021

I did this in a rush.  See if it works for you. 

 

Open a new document before running the script.  Units are in points. 

 

var ws = [], hs = [], n;
var dialog1 = new Window("dialog");
    dialog1.add("statictext", undefined, "How many artboards?");
var input1 = dialog1.add("edittext", undefined, "n");
    input1.characters = 4;
    input1.active = true;
    input1.onChange = function () {n = Number(input1.text);};
var button1 = dialog1.add("button", undefined, "Next");
    button1.onClick = function () {
        var dialog2 = new Window("dialog");
        for (var i = 0; i < Math.min(n, 20); i++) {
            (function() {
                var group = dialog2.add("group");
                group.add("statictext", undefined, "#" + (i + 1));
                var w = group.add("edittext", undefined, "w");
                    w.characters = 4;
                    w.onChange = function () {ws.push(w.text);}
                group.add("statictext", undefined, "x");
                var h = group.add("edittext", undefined, "h");
                    h.characters = 4;
                    h.onChange = function () {hs.push(h.text);}
            } ());
        }
        var button2 = dialog2.add("button", undefined, "OK");
        dialog2.show();
        dialog1.close();
    };
dialog1.show();
var doc = app.activeDocument;
var AR = doc.artboards[0].artboardRect = [0, 0, ws[0], - hs[0]];   
for (var i = 1; i < n; i++) { 
    doc.artboards.add([AR[0], AR[3] - 10, ws[i], (AR[3] - 10 - hs[i])]);
    AR = doc.artboards[i].artboardRect;  
}
Participant
September 19, 2021

Thats works!! Thank you so much, femkeblanco 🙂

GerssonDelgado
Inspiring
September 16, 2021

try this

 

function makeArtboardGroupItems() {
  if (app.documents.length == 0) {
    alert("No Open / Active Document Found");
  } else {
    var i, ii, iii, iv, doc, count, itemList, countArtboards, artboardIndex, tableError;
    doc = app.activeDocument;
    app.executeMenuCommand('selectall');
    itemList = doc.pathItems;
    for (i = 0, count = itemList.length; i < count; i++) {
      if (itemList[i].selected) {
        var box = itemList[i].visibleBounds;
        var ab = doc.artboards.add(box);
      }
    }
    doc.selection = null;
    app.redraw();

  }
}
makeArtboardGroupItems();
Participant
September 16, 2021

Thank you Delgado, but Nothing is happening 😞 appreaciate your help ❤️

I imagine something like this: 

 

When I click on script, small windows pops out, where at first I need to write how many artboards theres gonna be, and after entering the amount, you get as many rows as artboards were written above. Filling in dimensions and clicking Generate or smth like that.

 

Is it a big of a deal? 

femkeblanco
Legend
September 16, 2021

How are the artboards to relate to each other (rows, columns, space between, et cetera)?