• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

Script: rename layers?

Community Beginner ,
Feb 15, 2010 Feb 15, 2010

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

TOPICS
Scripting

Views

34.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guru , Feb 16, 2010 Feb 16, 2010

#target illustrator

var docRef = app.activeDocument;

with (docRef) {

     for (var i = 0; i < layers.length; i++) {

          layers.name = layers.length - i;

     }

}

Votes

Translate

Translate
Adobe
Community Beginner ,
May 24, 2017 May 24, 2017

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 15, 2020 Jan 15, 2020

Copy link to clipboard

Copied

LATEST

It didn't work for me.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 16, 2010 Feb 16, 2010

Copy link to clipboard

Copied

happy to have found this — thanks!!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 05, 2012 Jul 05, 2012

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 05, 2012 Jul 05, 2012

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.

Screen shot 2012-07-05 at 5.34.38 PM.png

Screen shot 2012-07-05 at 5.34.52 PM.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Apr 17, 2015 Apr 17, 2015

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 ?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 13, 2015 Jul 13, 2015

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();

}

}

Screenshot 2015-07-13 11.58.19.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jul 13, 2015 Jul 13, 2015

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 13, 2015 Jul 13, 2015

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jul 13, 2015 Jul 13, 2015

Copy link to clipboard

Copied

I use Layers Control 2; although as of PsCC-2015 it isn't stable

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 13, 2015 Jul 13, 2015

Copy link to clipboard

Copied

try this script, it renames sublayers as well

Re: Reworking Photoshop layer renaming script for Illustrator

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 20, 2016 Feb 20, 2016

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Feb 21, 2016 Feb 21, 2016

Copy link to clipboard

Copied

I was playing with this mid last year, it may do what you want.

aaa.JPG

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;

    }

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 05, 2016 Dec 05, 2016

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. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Dec 07, 2016 Dec 07, 2016

Copy link to clipboard

Copied

Go though all Visible layers & sub-layers and rename them would probably be faster then doing it manually.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 18, 2017 Jan 18, 2017

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).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 18, 2017 Jan 18, 2017

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Feb 27, 2017 Feb 27, 2017

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Mar 01, 2017 Mar 01, 2017

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...

scripts.qwertyfly.com

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Mar 03, 2017 Mar 03, 2017

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Mar 03, 2017 Mar 03, 2017

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Mar 03, 2017 Mar 03, 2017

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Mar 04, 2017 Mar 04, 2017

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Mar 04, 2017 Mar 04, 2017

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. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Mar 04, 2017 Mar 04, 2017

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...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines