Copy link to clipboard
Copied
Hi, is there a quick way how to renumber or batch rename all layers in a file so they would be named in consequent numbers? Doesn't have to start from exact number, I was wondering if maybe there is some sort of script that would help me with that? Thanks Pavel
#target illustrator
var docRef = app.activeDocument;
with (docRef) {
for (var i = 0; i < layers.length; i++) {
layers.name = layers.length - i;
}
}
Copy link to clipboard
Copied
Hi, Is there a way to number the layers for odd/even numbers: 1, 3, 5, etc. or 2, 4, 6, etc. Thank you!
Copy link to clipboard
Copied
It didn't work for me.
Copy link to clipboard
Copied
happy to have found this — thanks!!
Copy link to clipboard
Copied
I'm new to scripting in Illustrator. How do I get this to run? I copy and pasted the code into a text editor and saved it with a .jsx suffix. But nothing happens when I run it in Illustrator CS6.
Copy link to clipboard
Copied
Does your file structure follow the one outlined in the thread. Here's an example of what will happen with this script.
Copy link to clipboard
Copied
Is it possible to add prefix and suffix to the layer name ? Another idea is you select your layers and a dialog pops up and you enter in sequential order the name you want for the layers ?
Copy link to clipboard
Copied
Hi I am trying to modify this script by changing the 'ca' to something else more relevant to my project in this case 'PBW'. But I get this error whenever I change it.
could someone tell me why this is happening? I would love to be able to rename layers and change the names according to my project.
#target illustrator
var docRef = app.activeDocument;
with (docRef) {
for (var i = 0; i < layers.length; i++) {
layers.name = 'ca' + (layers.length - i).toString();
}
}
#target illustrator
var docRef = app.activeDocument;
with (docRef) {
for (var i = 0; i < layers.length; i++) {
layers.name = ‘PBW’ + (layers.length - i).toString();
}
}
Copy link to clipboard
Copied
It would be nice to be able to rename sub-layers with this script
Alan I'd like to see what you come up with; I have many script ideas for Ps and or Illustrator; I'm learning Ps DOM and not going as fast as I had planned
Copy link to clipboard
Copied
Hey StrongBeaver, I didn't write this script, just copied it from a post above. I found out what was wrong when I was trying to modify it this afternoon. Text edit was replacing single quotes with curly quotes 'ca' or 'PBW' or 'insert your text here'. I had to turn off smart quotes in text edit and it works perfectly now. If you need layer renaming in photoshop I would suggest using Renamy http://klaia.com/Renamy/ they just updated for PS_2015. Its friggan amazing. Too bad theres not something like Renamy for AI.
Copy link to clipboard
Copied
I use Layers Control 2; although as of PsCC-2015 it isn't stable
Copy link to clipboard
Copied
try this script, it renames sublayers as well
Re: Reworking Photoshop layer renaming script for Illustrator
Copy link to clipboard
Copied
I read all of the above, but I didn't quite find out if there is a script available to only rename selected layers with the option to add a prefix. This would be a very good script to have in the arsenal Anyone know where to look? Is it difficult to make?
Copy link to clipboard
Copied
I was playing with this mid last year, it may do what you want.
var doc = app.activeDocument, lays = [];
for(var i = 0; i < doc.layers.length; i++){
lays.push(doc.layers.name);
}
var w = new Window('dialog',"Layer Name Editor");
var list = w.add('group');
list.orientation = "Column";
var head = list.add('group');
head.alignment = "left";
var p = head.add('statictext', undefined, "Prefix");
var n = head.add('statictext', [0,0,165,20], " Layer Name");
var s = head.add('statictext', undefined, "Suffix");
var pre = [], nam = [], suf = [];
for(var i = 0; i < lays.length; i++){
newLine(i,"item" + i);
}
function newLine(num,item){
item = list.add('group');
item.alignment = "left";
pre[num] = item.add('checkbox', undefined,"");
nam[num] = item.add('edittext', [0,0,200,20], lays);
nam[num].characters = 50;
suf[num] = item.add('checkbox', undefined, "");
}
var sep1 = list.add("panel");
sep1.alignment = ["fill","fill"];
sep1.minimumSize.height = sep1.maximumSize.height = 2;
var prefixt = list.add('statictext', undefined, "Prefix to add to checked layers");
var prefix = list.add('edittext', [0,0,250,20], "");
var sep2 = list.add("panel");
sep2.alignment = ["fill","fill"];
sep2.minimumSize.height = sep2.maximumSize.height = 2;
var prefixt = list.add('statictext', undefined, "Suffix to add to checked layers");
var suffix = list.add('edittext', [0,0,250,20], "");
var sep3 = list.add("panel");
sep3.alignment = ["fill","fill"];
sep3.minimumSize.height = sep3.maximumSize.height = 2;
var ButtonGroup = w.add("group");
ButtonGroup.margins = [0,-10,0,-8];
ButtonGroup.alignment = "right";
var go = ButtonGroup.add ("button", undefined, "OK");
var stop = ButtonGroup.add ("button", undefined, "Cancel");
stop.onClick = function(){
w.close();
}
go.onClick = function(){
var validatePre = false, validateSuf = false, validateMessage = "";
for(var i = 0; i < lays.length; i++){
if(pre.value == true && prefix.text == ""){validatePre = true}
if(suf.value == true && suffix.text == ""){validateSuf = true}
}
if(validatePre == true){validateMessage = "Layers have been marked for Prefix, but no Prefix entered\n"}
if(validateSuf == true){validateMessage = validateMessage + "Layers have been marked for Suffix, but no Suffix entered"}
if(validateMessage != ""){
alert(validateMessage);
}else{
w.close();
goTime();
}
}
w.show();
function goTime(){
for(var i = 0; i < lays.length; i++){
var na = nam.text;
var pr = "";
var su = "";
if(pre.value == true){pr = prefix.text + " - "}
if(suf.value == true){su = " - " + suffix.text}
doc.layers.name = pr + na + su;
}
}
Copy link to clipboard
Copied
And how might I go about adding a script to that one, to only edit visible layers?
Like inserting this from the comments above?
if (layers.visible == true) // <--- Testing .. 1,2,3.
{
Copy link to clipboard
Copied
Go though all Visible layers & sub-layers and rename them would probably be faster then doing it manually.
Copy link to clipboard
Copied
Just logged in to say thank you, to all the contributors here, especially Qwertyfly... (I just used your script today).
Copy link to clipboard
Copied
Whoops, ran into a hiccup though, that comes up because of the kind of anims I'm doing (importing AI files into After Effects, using them as moving elements).
Qwertyfly...'s script's dialog box shows all the documents layers. When I added a few dozen more layers, the script became unusable because the dialog box ain't resizable and has no scroll bars.
I think tomorrow I'll do a workaround and just save a copy of the AI file, delete the layers I don't want to rename, run this script, and paste the results into my 'real' AI file.
Copy link to clipboard
Copied
adding a scroll bar to this should not be too much work.
the other option would be to rename selected layers.
the roundabout method for accessing selected layers is looked at here: Re: Select only highlighted layers?
this could be incorporated along side a scrollbar, and maybe a select all would be good.
I will see if I can add these without too much work.
Copy link to clipboard
Copied
Ok, no scroll bar, Why?. because ScriptUI is a nightmare.
simple solution... TABS.
no prizes for the application of material design.
but its functional.
hope this help's...
Copy link to clipboard
Copied
The tabs are not prominent enough, although this may be the style of ScriptUI ? As well the script has crashed on me twice in 21.0.2.
Copy link to clipboard
Copied
the tabs style is set by scriptUI.
scriptUI is not fun to work with.
as for the crashes.
can you explain 21.0.2?
do you know where it crashed?
are you running it standalone. or from ESTK
thanks for the feedback.
any extra info would really help in making it more stable.
Copy link to clipboard
Copied
The script is being run standalone. I began the script, enabled prefix and suffix for a few layers, gave those layers a prefix and suffix name to change for the layer; clicked OK and Illustrator crashed, I did the same steps and each and every time I would crash Illustrator.
Copy link to clipboard
Copied
I can't get it to crash.
only got 2015.3 on this machine, adding 2017 now and will test that as well.
can you provide any system info.
mac or pc?
you are using this for illustrator yes?
which illustrator version?
is your system default language English.
are there any strange characters in any of the layer names?
How many layers?
Thanks heaps.
Copy link to clipboard
Copied
I'm running 2017 on a PC, and yes I'm using this script with Illustrator (21.0.2) The language of the system is English. The only characters that exist in the layer names are underscores & there are over ten layers.
Copy link to clipboard
Copied
Ok I just installed 2017.
I had not seen this yet as I have been busy with other things.
WOW what a difference.
I am guessing things have changed a bit...
scriptUI was ugly at best.
now it is terrible. as you say the tabs are crap, and the check boxes are near invisible!
and it crashed!
just starting the script and pressing cancel crashed it.
as I have had a few issues getting 2017 to open without crashing, its still taking about 7-8min to start up.
I am in no way confident of the cause.
I may need to revisit the code and jig it to work with the new illy, I will need to learn what does not work now.
Watch this space...