2

I tried to create an action to automate "duplicate artboard" in Illustrator CC but it was not possible. I would like to know if there is any script to do this. enter image description here

Thanks

3

Yea the problem is, it's not a recordable action, and while it appears simple on the surface, there's apparently a lot to duplicating an artboard. But, you can augment the code with your needs. This snippet will make a new artboard and use copy/paste to put the items on the new artboard. If the new artboard happens to be off the side of the pasteboard, that's a code edit. If you happen to have 1000 artboards already and adding the next one throws an error or causes a crash, that's a code edit. If you have a problem with how it trashes your existing selection, or clipboard, you better believe that's a code edit!

But here is my simple sample!

#target illustrator
function test(){
    var doc = app.activeDocument;
    var thisBoardIndex = doc.artboards.getActiveArtboardIndex();
    var thisBoard = doc.artboards[thisBoardIndex];
    var thisRect = thisBoard.artboardRect;
    var lastBoard = doc.artboards[doc.artboards.length - 1];
    var lastRect = lastBoard.artboardRect;
    doc.selectObjectsOnActiveArtboard();
    app.copy();
    var newBoard = doc.artboards.add(thisRect);
    var offsetH = 20;
    newBoard.artboardRect = [
        lastRect[2] + offsetH,
        lastRect[1],
        lastRect[2] + offsetH + (thisRect[2] - thisRect[0]),
        lastRect[3]
    ];
    newBoard.name = thisBoard.name + " copy";
    app.executeMenuCommand("pasteFront");
    doc.selection = null;
};
test();
  • My friend, what you did works perfectly for me. I tried to get the content pasted into a new layer, but it did not work. Do you have a solution for this? If you not have, no problem, you've helped a lot. I added targetLayer = doc.layers.add(); – Douglas Bicalho Feb 6 '18 at 13:14
  • 1
    Then you'd have to do a loop and move all of the selection into the new layer, after the pasteFront command runs and before you deselect things. The loop may need to go backwards: for(var i = doc.selection.length - 1; i > -1; i--), and the move command is like this: doc.selection[i].move(targetLayer, ElementPlacement.PLACEATEND); – Silly-V Feb 6 '18 at 16:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.