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

2 Answers 2

4

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();
4
  • 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(); Commented Feb 6, 2018 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
    Commented Feb 6, 2018 at 16:45
  • @Silly-V Throws the following error when I run the script: Error 1200: an illustrator error occured.... Line 13: -> newBoard.artboardRect = [. Is it possible to fix this?
    – Devner
    Commented Jul 25, 2020 at 19:34
  • Sorry, I can't reproduce this error at all. Maybe it's got something to do with the way your document is laid out?
    – Silly-V
    Commented Jul 25, 2020 at 20:37
-1

For Coping the layer as crazy as it is that one is a recordable action so you could use that to copy the layer then run the action as a batch on the needed folder.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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