Link in Zwischenablage kopieren
Kopiert
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;
...
Link in Zwischenablage kopieren
Kopiert
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();
Link in Zwischenablage kopieren
Kopiert
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
Link in Zwischenablage kopieren
Kopiert
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?
Link in Zwischenablage kopieren
Kopiert
yeah right, that's what I mean
Link in Zwischenablage kopieren
Kopiert
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?
Link in Zwischenablage kopieren
Kopiert
here the file:
Link in Zwischenablage kopieren
Kopiert
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();
Link in Zwischenablage kopieren
Kopiert
wow thank you so much
Link in Zwischenablage kopieren
Kopiert
No problem. hope it helps.
Link in Zwischenablage kopieren
Kopiert
Link in Zwischenablage kopieren
Kopiert
try copying the script again, I just fixed the error on William's script
Link in Zwischenablage kopieren
Kopiert
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!
Link in Zwischenablage kopieren
Kopiert
Hi, do you have multiple artboards and you want to put all of them on top of each other like pancakes?
Link in Zwischenablage kopieren
Kopiert
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 🙂
Link in Zwischenablage kopieren
Kopiert
see if any of these two methods work for you
Link in Zwischenablage kopieren
Kopiert
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!
Link in Zwischenablage kopieren
Kopiert
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).
Link in Zwischenablage kopieren
Kopiert
Thank you so much! This script is awesome.
Link in Zwischenablage kopieren
Kopiert
This works really well, but it does appear to create each layer twice, in my case I had 43 artboards, and now I have 86 Layers where half of them are empty and easy to clean up, but I figured I'd mention it.
I'm using Illustrator 2024 for this
Link in Zwischenablage kopieren
Kopiert
Not sure why I can't edit my comments, but it turns out my script panel is for some reason executing every script twice all of a sudden, so your script wasn't at fault here, my bad
Link in Zwischenablage kopieren
Kopiert
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
Link in Zwischenablage kopieren
Kopiert
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.
Link in Zwischenablage kopieren
Kopiert
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!
Link in Zwischenablage kopieren
Kopiert
I got an error using this script. 😞
Error 1302 : No such element line
ab.name = doc.layers.name;
Weitere Inspirationen, Events und Ressourcen finden Sie in der neuen Adobe Community
Jetzt ansehen