Tuesday, July 2, 2019

Duplicate artboard with script Illustrator CC



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



Answer



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

No comments:

Post a Comment

technique - How credible is wikipedia?

I understand that this question relates more to wikipedia than it does writing but... If I was going to use wikipedia for a source for a res...