Copy link to clipboard
Copied
I am unable to find a script that will do this. The default application functionality is really frustrating how it just slaps a generic "Layer 1", "Layer 2" layer name on the new layers. I would rather have the name of the sublayer become the name of the new layer. Has anyone seen a script anywhere that does this?
you need to copy and paste the code into any text editor and save it as jsx
Installing scripts in the Scripts menu
To include a script in the Scripts menu (File > Scripts), save the script in the Scripts folder, located in the
/lllustrator CC/Presets folder in your lllustrator CC installation directory. The script’s filename, minus
the file extension, appears in the Scripts menu.
Scripts that you add to the Scripts folder while Illustrator is running do not appear in the Scripts menu until
the next ti
...Copy link to clipboard
Copied
Hey Jass,
Thanks for the answer.
It still doesnt work for me, I dont understand. I follow all the steps and the same error keeps coming up. Really annoying. Any further help would be super appreaciated.
Thanks
Gemma
Copy link to clipboard
Copied
Hi Gemma, what's the error you're getting?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
ok, then the script works. Make sure your layers are setup like the file that had no issues running the script on.
or follow the below steps
1. your layers should look like this
2. select Layer 1 then do Release to Layers (sequence)
3. keep Layer 1 selected then run the script, your layers should look like this
enjoy
Copy link to clipboard
Copied
Might not be relevant but I was initially getting an error as I'd copied Carlos' text into Text Edit (I'm on a Mac) before saving out as a .jsx file.
Problem was, I'd left it as Rich text. Once I'd formatted it to plain text and resaved, bingo.
Copy link to clipboard
Copied
Many, many years later, amazing, thanks Carlos!
Copy link to clipboard
Copied
It's crazy that this is still an issue, but also, thanks from me, Carlos! And thanks, Simon, for mentioning the "rich text" issue; it helped me a lot. 🙂
Copy link to clipboard
Copied
If anyone is out there still having the 1302 error, editing the code like this worked for me. It had to do with the type of layer inside my layers, if that makes sense. I just removed pageItems. Here's the edit:
var idoc = app.activeDocument;
var ilayer = idoc.activeLayer;
for (i=0; i<ilayer.layers.length; i++)
{
var sublayer = ilayer.layers[i];
sublayer.name = sublayer[0].name;
}
Copy link to clipboard
Copied
Well it worked for some of my layers. I edited the code further so that it tries both types and if it doesn't work it just skips them. @CarlosCanto sorry to bother you. Any ideas?
var idoc = app.activeDocument;
var ilayer = idoc.activeLayer;
for (i=0; i<ilayer.layers.length; i++)
{
var sublayer = ilayer.layers[i];
try {
sublayer.name = sublayer.pageItems[0].name;
}
catch(err) {
try {
sublayer.name = sublayer[0].name;
}
catch(err) {
// pass
}
}
}
Copy link to clipboard
Copied
Got it working. Here's code:
var idoc = app.activeDocument;
var ilayer = idoc.activeLayer;
for (i=0; i<ilayer.layers.length; i++)
{
var sublayer = ilayer.layers[i];
try {
sublayer.name = sublayer.pageItems[0].name;
}
catch(err) {
try {sublayer.name = sublayer.layers[0].name;
}
catch(err) {
alert(err);
}
}
}
Copy link to clipboard
Copied
Copy link to clipboard
Copied
All the issues I had were to do with the types of "layers" I was trying to get the names from. For some of my "layers" they weren't actually considered layers, but groups or lines or something. That's why I put the error checking with pageItems because I discovered that Illustrator considered some of my "layers" with the names to be pageItems instead of actual layers. I would suggest learning more about that so you can customize the code to work with your project. Or perhaps you can create new literal layers and put all your stuff in them and then try it, but that kind of defeats the purpose of the code.
Copy link to clipboard
Copied
Thank you for this!
Copy link to clipboard
Copied
Maybe I am missing something here, but when i run the .jsx file it does nothing.
Can anyone help?
Copy link to clipboard
Copied
make sure your layout is similar to the screenshot I posted here