Copy link to clipboard
Copied
I am trying to automate a workflow process that I recently developed, focussed on improving the design process in illustrator using artboards but while still optimizing the transfer of artwork to after effects for animation. My goal is to develop a script that will 1) create new artboards for each separate layer (not the sublayers) and also match the name of the newly created artboard to the referenced layer (not required but it would be nice). Then make symbols for each layers artwork and place it on the newly created artboard. And lastly create a new layer, called something like "symbols collection" where each of the layer symbols will be placed. I am still pretty novice when it comes to scripting, but I am good enough as decoding existing scripts, so I am using William Campbell's repeat artboard as a basis with the first step, creating artboards for each layer. I don't believe there is a method for setting the newly created artboard name though. I can get the layer names, and I can get the artboard names, but I am not entirely sure how to make that connection between them. Then there is the question of automating the symbol conversion. This alone could be a huge time saver and possibly be enough to make the workflow automation sufficient. If anyone has any scripts that relate, or suggestions for methods, I would very much appreciate any and all input I can get!
HI @Sethj78737,
Could you please try the following version?
var doc = app.activeDocument;
var gout = 10;
var dx, dy;
dx = dy = 0;
var ab = doc.artboards[0];
var _symbolsArray = new Array();
var _layers = doc.layers;
for (var l = 0; l < _layers.length; l++) {
if (_layers[l].visible) {
var rect = ab.artboardRect;
var W = doc.width;
var H = doc.height;
dx = W + gout;
//Create a new artboard
var ab = doc.artboards.add([rect[0] + dx, rect[1], rect
...
Copy link to clipboard
Copied
Hi @Sethj78737 , try following script. It may not be perfect version, as we can more validations to it. I ahve added a sample document as well on which I test the script.
var doc = app.activeDocument;
var gout = 10;
var dx, dy;
dx = dy = 0;
var ab = doc.artboards[0];
var _symbolsArray = new Array();
var _layers = doc.layers;
for (var l = 0; l < _layers.length; l++) {
var rect = ab.artboardRect;
var W = doc.width;
var H = doc.height;
dx = W + gout;
//Create a new artboard
var ab = doc.artboards.add([rect[0] + dx, rect[1], rect[0] + dx + W, rect[3]]);
ab.name = _layers[l].name; // Give same name ti artboard as layer
var _pageItems = _layers[l].pageItems;
app.executeMenuCommand('deselectall');
for (var p = 0; p < _pageItems.length; p++) {
_pageItems[p].translate(ab.artboardRect[0] + 10, dy);
}
app.redraw();
//Create symbol of items for new artboards
if (_pageItems.length) {
doc.artboards.setActiveArtboardIndex(l + 1);
app.executeMenuCommand('selectallinartboard');
app.executeMenuCommand('group');
var _selectedItem = app.selection[0];
var _symbol = doc.symbols.add(_selectedItem);
var _placedSymbol = doc.symbolItems.add(_symbol);
_placedSymbol.position = _selectedItem.position;
_symbolsArray.push(_placedSymbol);
// _selectedItem.remove() //Uncomment if you want to remove item from which symbol is created
}
}
//Move all placed symbols to new layer 'symbols collection'
var symbolLayer = doc.layers.add();
symbolLayer.name = 'symbols collection';
for (var s = 0; s < _symbolsArray.length; s++) {
_symbolsArray[s].move(symbolLayer, ElementPlacement.PLACEATEND);
}
app.executeMenuCommand('deselectall');
Hope it helps and you can modify it as required.
Copy link to clipboard
Copied
Hi Charu,
Thanks so much for sharing this attempt at the script...I was able to get the creation of the artboards per layer, so now I am going to try and convert the layer content to symbols. I tried running yours and it errors at line #31 required value is missing. Error 1242 - Illegal argument , var _symbol = doc.symbols.add(_selectedItem). Thoughts on what might be causing this??
Copy link to clipboard
Copied
Is this error in the same document, that I have shared or some another document?
Or you can try by adding a line
app.redraw();
before
var _selectedItem = app.selection[0];
Let me know how it goes.
Copy link to clipboard
Copied
Hi Charu,
I am not seeing a shared document, so I was trying to apply the script to me test document. I went ahead and added the app.redraw() as well and it's still erroring at the doc.sybols.add(_selectedItem) line, with an Illegal argument error, "required value is missing". I tried troubleshooting it myself and limited the script to perform just the section that is creating the symbols for each layer, but that wasn't working either and I am not completely sure how to approach troubleshooting it, as the Illustrator scripting guide doesn't provide a lot of context for syntax. Any other suggestions would be greatly appreciated!
Cheers,
Seth
Copy link to clipboard
Copied
Hi,
Oops, I am sorry, there was an error while attaching an ai file. I did not noticed earlier.
Here is the link for the test file.
https://drive.google.com/file/d/1Js2dg1y5tfRHuEFXEi8wCSxYcjWWHpUW/view?usp=sharing
Could you please share your sample file?
Copy link to clipboard
Copied
Hi Charu,
I tried it again on the test file you provided and still get the error. I have included a screenshot of the error I have been referencing. I went ahead and included my test file as well, for reference. I am having trouble using the scripting guide to identify the correct syntax to use, so that I can focus on just one element at a time. I can create the new artboards with the script and have them named according to the existing layers, but I can't create the symbols per layer, so that is where I am ultimately stuck. Thanks for taking the time to review this with me! Very much appreciated. If you have any suggestions for learning resources, to bridge that gap between the scripting guide and the approach to script structure, I would be very interested in learning more. Thanks again!
Copy link to clipboard
Copied
Looks like the illustrator file won't link so here is the drive link.
https://drive.google.com/file/d/1XbY5LzuY6Afb4oNL3XJUCYC8DEu01ZVv/view?usp=sharing
Copy link to clipboard
Copied
HI @Sethj78737,
Could you please try the following version?
var doc = app.activeDocument;
var gout = 10;
var dx, dy;
dx = dy = 0;
var ab = doc.artboards[0];
var _symbolsArray = new Array();
var _layers = doc.layers;
for (var l = 0; l < _layers.length; l++) {
if (_layers[l].visible) {
var rect = ab.artboardRect;
var W = doc.width;
var H = doc.height;
dx = W + gout;
//Create a new artboard
var ab = doc.artboards.add([rect[0] + dx, rect[1], rect[0] + dx + W, rect[3]]);
ab.name = _layers[l].name; // Give same name ti artboard as layer
var _pageItems = _layers[l].pageItems;
app.executeMenuCommand('deselectall');
for (var p = 0; p < _pageItems.length; p++) {
_pageItems[p].position = new Array(ab.artboardRect[0] + 10, (ab.artboardRect[1]));
// _pageItems[p].translate(ab.artboardRect[0] + 10, dy);
}
app.redraw();
//Create symbol of items for new artboards
if (_pageItems.length) {
doc.artboards.setActiveArtboardIndex(l + 1);
app.executeMenuCommand('selectallinartboard');
app.executeMenuCommand('group');
var _selectedItem = app.selection[0];
var _symbol = doc.symbols.add(_selectedItem);
var _placedSymbol = doc.symbolItems.add(_symbol);
_placedSymbol.position = _selectedItem.position;
_symbolsArray.push(_placedSymbol);
// _selectedItem.remove() //Uncomment if you want to remove item from which symbol is created
}
}
}
//Move all placed symbols to new layer 'symbols collection'
var symbolLayer = doc.layers.add();
symbolLayer.name = 'symbols collection';
for (var s = 0; s < _symbolsArray.length; s++) {
_symbolsArray[s].move(symbolLayer, ElementPlacement.PLACEATEND);
}
app.executeMenuCommand('deselectall');
Copy link to clipboard
Copied
Hi Charu,
This is amazing progress, thanks so much for the update. I am still running into a few issues with the script. The placement of the original artwork layers is going to the top left corner of the artboards that have just been created. So all of the layers are overlapping. And only the first layer (location) is generating a symbol, but it's doing it three times. I am not sure but I thought perhaps this code was responsible for the placement of the artwork...
for (var p = 0; p < _pageItems.length; p++) {
_pageItems[p].position = new Array(ab.artboardRect[0] + 10, (ab.artboardRect[1]));
But when I try to comment this out, it is causing the code not to run correctly. The goal is to keep the original artwork in that beginning position (on each of their original layers, on the master artboard (Artboard 1), which is where we will be exporting to after effects from). So we want to create the symbol items on the new artboards in the same relative positions (centered I'm guessing)...so that we can work from the artboards, but export them all from the first artboard as a single file. I will pick away at this, since at least now the symbols are being created and that has been hanging me up for the past few days. If you're open to exploring this further, it's very much appreciated, but thanks either way for sharing your time and this code as a jumping off point! Cheers!