Copy link to clipboard
Copied
Copy link to clipboard
Copied
here's a script to rename Sublayers (based on the first object's name), do it like this
1. release layers (ie Layer 1)
1.1 activate (highlight) layer (Layer 1)
1.2 run script
2. select them all...
3. drag the whole bunch...
// renameSublayers.jsx - carlos canto
// http://forums.adobe.com/message/5403549?tstart=0#5403549
var idoc = app.activeDocument;
var ilayer = idoc.activeLayer;
for (i=0; i<ilayer.layers.length; i++) {
var isublayer = ilayer.layers;
isublayer.name = isublayer.pageItems[0].name;
}
Copy link to clipboard
Copied
Hi, Carlos.
I tried using your script following your instructions but the sublayers name only change to "<Layer>"
Copy link to clipboard
Copied
the sublayer will copy the name of the first object, if this object has no name, the layer takes the default name "<layer>"
Copy link to clipboard
Copied
Thanks for the quick response Carlos. But I selected and previusly named the respective layer and then run your script and still get in return only the "<Layer>" name.
I copied your script in a Note Block document and save it as an .jsx document. Then run it in Ilustrator CC (17.0) from the File Menu / Scripts / Other Scripts...
Am I doing it wrong?
Copy link to clipboard
Copied
The object in the layer needs to be named, the script will get that name and apply it to the layer
Copy link to clipboard
Copied
Carlos, thanks for your renameSublayers script. Would it be possible to modify it so that it also works with text objects that have not been manually named by the user? I have about a hundred sublayers called Layer 1, Layer 2 etc and inside each one is a single text object such APPLE, PEAR etc which derive their names from the actual text itself - your script cannot seem to see these names unless I manually rename the text objects in the layer panel. Hope that makes sense. Steve
Copy link to clipboard
Copied
yes, this version works with either Named or Unnamed text items
// carlos canto // 09/26/14
// https://forums.adobe.com/thread/287812
var idoc = app.activeDocument;
var ilayer = idoc.activeLayer;
for (i=0; i<ilayer.layers.length; i++) {
var sublayer = ilayer.layers;
sublayer.name = sublayer.pageItems[0].name || sublayer.pageItems[0].contents;
}
Copy link to clipboard
Copied
This is brilliant! Thanks so much. Dealing with long lists of words (separated into text objects) that I need to separate into Layers for After Effects. Much easier to work with them in AE if they have WYSIWYG layer names.
Copy link to clipboard
Copied
Hi Carlos
I've saved the script and tried to run it, but I'm getting this error:
this is a screen cap of my file structure
so I grabbed my Layer 50, did a release to layers, and have what you see above. I then selected Layer 50, and tried to run the script and got the error. Can you give me some guidance in what I'm doing wrong?
Thanks!!
Copy link to clipboard
Copied
you're not doing anything wrong, the script was meant to be used for text items only, it seems you have paths in layer 51
try this version
// http://forums.adobe.com/thread/877442?
// http://forums.adobe.com/thread/1408454?tstart=0
// carlos canto // 09/26/14
// https://forums.adobe.com/thread/287812
var idoc = app.activeDocument;
var ilayer = idoc.activeLayer;
for (i=0; i<ilayer.layers.length; i++) {
var sublayer = ilayer.layers;
sublayer.name = sublayer.pageItems[0].contents || sublayer.pageItems[0].name;
}
Copy link to clipboard
Copied
Carlos - you are a legend. Thanks dude, you've saved me A LOT of time!
Copy link to clipboard
Copied
This ancient thread is still very relevant. I used the script from post #6 and now have a nice top-level layered AI file that I can import into After Effects. Thanks!
Copy link to clipboard
Copied
Thanks Carlos. Unfortunately, I'm still having trouble with it, but I think it might be due to the fact that the files I deal with are a mixture of text and paths.
Copy link to clipboard
Copied
can you share a file? if so, upload it to your favorite host and post a link here.
Copy link to clipboard
Copied
Unfortunately, I can't post an actual file because it's confidential, but I'll see if I can find some time to build something similar to post up here.
Copy link to clipboard
Copied
Hi Murgiddy,
I've just had a go using a mixture of paths and texts (threw in a rectangle for good measure) and it all seemed to work fine.
These are my steps:
Before
Release to layers (with Top layer and circle highlighted)
Select Top layer again (again with circle selected)
File -> Scripts -> Other Scripts - select the exceptionally handy script Carlos has made
Layers now named after their sub layer name
Are you doing anything differently?
Copy link to clipboard
Copied
cubkent,
That worked for me! I'm not exactly sure what I was doing differently before (possibly not having the circle selected???) but it appears to be working now. I guess I just needed to follow it step by step...I'm a CG artist, so AI isn't my strongest software
Thanks again!
Copy link to clipboard
Copied
No problem, yeah I was having issues until I selected everything I could about the layer! Glad it's working for you know.
Thanks again Carlos.
Copy link to clipboard
Copied
you're welcome, glad to hear it's working for everyone now, thanks for helping out with screen shots.
Copy link to clipboard
Copied
Hi guys, Im joining to this thread.
I use carlos' loop to set the sub-layers to top-layers, and its works very well.
My problem/question:
Has anyone found a script-command to make the "release to layers" task automatically? (It is necessary for my main script, I cant do it manually.)
Something like:
app.executeMenuCommand('COMMAND HERE');
Maybe its just 'releasetolayers', but I have no english version of Illustrator here, so please tell me, if my approach is correct.
Cheers
Copy link to clipboard
Copied
there may not be a command string for release to layers, as an alternative, you could record an Action, then have your script run the action to release to layers.
Copy link to clipboard
Copied
Thanks carlos,
that might work.
I didnt know about the app.doScript() function before.
I will test this scenario.
Copy link to clipboard
Copied
Carlos - Thanks for this script. Amazing!!!
Copy link to clipboard
Copied
Thanks CarlosCanto, this is fantastic! May I share this script with colleagues? I just copied all your lines of code and would send them the jsx file.
Copy link to clipboard
Copied
Sure Rene Andritsch, go adhead