Copy link to clipboard
Copied
Hello everyone, I have this script to convert multiple layers to multiple artboards, and also copy each layer name to artboards.
The problem is how to reserve the this script process?
I mean to converts artboards to layer and copy artboards name to layer. Thanks
#target illustrator
main();
function main() {
if ( app.documents.length == 0 ) { return; }
var doc = app.activeDocument;
doc.layers[0].hasSelectedArtwork = true;
doc.fitArtboardToSelectedArt( 0 );
doc.selection = null;
for ( var i = 1; i < doc.layers.length; i++ ) {
doc.artboards.add( [0,0,72,-72] );
doc.layers[i].hasSelectedArtwork = true;
doc.fitArtboardToSelectedArt( i );
doc.selection = null;
};
};
if (app.documents.length == 0) {
alert("No Open / Active Document Found");
} else {
var doc = app.activeDocument;
if (doc.artboards.length == doc.layers.length && doc.layers.length == doc.artboards.length) {
for (var i = 0, l = doc.artboards.length; i < l; i++) {
var ab = doc.artboards[i];
ab.name = doc.layers[i].name;
}
alert("Finished:\nRenaming of Artboards to match Layer names is complete");
} else {
alert("Opps: This wont work!\n The number of Layers and Artboards do not match");
}
}
Here you go.
function layersFromArtboards()
{
var docRef = app.activeDocument;
var layers = docRef.layers;
var aB = docRef.artboards;
//we will remove this layer after the others have been created.
var tempLay = layers[0];
tempLay.name = "Temp";
//loop the artboards
for(var x=0;x<aB.length;x++)
{
var thisAb = aB[x];
aB.setActiveArtboardIndex(x);
docRef.selectObjectsOnActiveArtboard();
var sel = docRef.selection;
...
Copy link to clipboard
Copied
Not sure exactly why yours didn't work, but that code was a little messy. it had multiple tests to determine whether a doc exists, and there are two loops where you could get away with one. Here's a snippet that i briefly tested and is working how you want, unless i misunderstand what you're asking for.
function container()
{
if(app.documents.length > 0)
{
var doc = app.activeDocument;
var layers = doc.layers
var artboards = doc.artboards;
for(var i=0;i<doc.layers.length;i++)
{
if(i>0)
{
var newAb = artboards.add([0,0,5,-5]);
}
var thisLayer = doc.layers[i];
thisLayer.hasSelectedArtwork = true;
doc.fitArtboardToSelectedArt(i);
artboards[i].name = layers.name;
doc.selection = null;
}
alert("Finished:\nRenaming of Artboards to match Layer names is complete");
}
else
{
alert("No Open / Active Document Found");
}
}
container();
Copy link to clipboard
Copied
Hi William, thank you for your answer, but its not what I want.
I want to reserve the script, from artboards to layers. Artboards >> Layers
Copy link to clipboard
Copied
I think something is getting lost in translation here. I don't believe i'm understanding.
Are you saying that you want to create one layer for each artboard and set the layer name to match the artboard name?
Copy link to clipboard
Copied
yeah right, that's what I mean
Copy link to clipboard
Copied
Ok. the necessary logic changes a lot then. We can't use methods like "layers[0].hasSelectedArtwork = true".
Do you have a sample file you can share so that I can be sure to account for the specifics of your file?
Copy link to clipboard
Copied
here the file:
Copy link to clipboard
Copied
Here you go.
function layersFromArtboards()
{
var docRef = app.activeDocument;
var layers = docRef.layers;
var aB = docRef.artboards;
//we will remove this layer after the others have been created.
var tempLay = layers[0];
tempLay.name = "Temp";
//loop the artboards
for(var x=0;x<aB.length;x++)
{
var thisAb = aB[x];
aB.setActiveArtboardIndex(x);
docRef.selectObjectsOnActiveArtboard();
var sel = docRef.selection;
//create a new layer
var newLay = layers.add();
newLay.name = thisAb.name;
//loop through the selection and move all artwork onto new layer
//this is only necessary if the artwork on a given artboard is not
//grouped. This ensures that all the art will be moved, even if there are
//multiple ungrouped objects.
for(var a=0;a<sel.length;a++)
{
sel[a].moveToEnd(newLay);
}
}
tempLay.remove();
}
layersFromArtboards();
Copy link to clipboard
Copied
wow thank you so much
Copy link to clipboard
Copied
No problem. hope it helps.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
try copying the script again, I just fixed the error on William's script
Copy link to clipboard
Copied
Thanks a bunch Carlos, it works like a charm now!
Actually I was expecting that each created layers would go on the first artboard, and not to stay on their respective ones as it is with William's script. Would you know any way to fix this?
Thanks again for your precious help!
Copy link to clipboard
Copied
Hi, do you have multiple artboards and you want to put all of them on top of each other like pancakes?
Copy link to clipboard
Copied
Yes, exactly. I wish to have all my artboards put on top of each other, in different layers, on a unique artboard. Like pancakes, as you put it so nicely 🙂
Copy link to clipboard
Copied
see if any of these two methods work for you
Copy link to clipboard
Copied
No, it doesn't, or not really. The "AI-merge" script doesn't open PDF files. I tried with AI files (by simply changing the extension of my PDF to .ai) and it worked fine, but even then it puts every document on its own layer (unless, like in the video, the artboard size is too small).
As for the other method, that is to Paste Remembers Layers, I use it regularly but that would involve much manual work. Having a large number of files to process, I wish I could find a script to automatise much of the work.
Once more, thanks zillions for your time!
Copy link to clipboard
Copied
Oops, one should read "but even then it puts every document on its own artboard" (not layer). Furthermore, I just find out that this script is not really precise and the location of each document on artboard varies of some 1 to 2 points (bad idea as my layers have to be very precisely aligned).
Copy link to clipboard
Copied
Thank you so much! This script is awesome.
Copy link to clipboard
Copied
Hi Williamadowling
I have used the layers to artboards script which is great and works really well, thank you so much. Is there a way of adding a 20mm edge to the new
Is there a way of adding a 20mm edge to the new artboards?
Thanks again
Copy link to clipboard
Copied
It's a good idea to create a new post for that. It helps keep the forum organized and makes it easier for someone else in the future who has the same question you have.
Copy link to clipboard
Copied
Ok thank you. I actually found a script to add a margin and then ran it as a batch action to all files.
Thanks again for the script!
Copy link to clipboard
Copied
I got an error using this script. 😞
Error 1302 : No such element line
ab.name = doc.layers.name;
Copy link to clipboard
Copied
I mean to the first script -- making artboards from layers.
Copy link to clipboard
Copied
try copy/pasting the script again, I just fixed the indexes of the script posted by azisher