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

script to rename layers alphabetically

New Here ,
Jun 28, 2013 Jun 28, 2013

Hi everyone,

I have a renaming script that works only on numbers and I want to make it work for letters also.

What I`m trying to achieve is to select some layers --> load the script --> enter the desired name of the layer and in brackets insert the letter from where to start. Then the script iterates through the alphabet renaming the layers and adding the coresponding letter to the name and removing the brackets. For example, I select 4 layers, load the script and when the prompt comes on... enter the name:      test . At the end I should have the layers renamed testC,testD,testE,testF

Any help would be appreciated!

Thanks

TOPICS
Scripting
1.3K
Translate
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

Community Expert , Jul 03, 2013 Jul 03, 2013

so, what you wanted is to rename Selected Objects, not Layers, right?

check this script, I took a different route, I added a couple of comments, if you have any trouble with it, feel free to ask

// this script Renames selected Objects with a base name plus an incremental suffix

// Carlos Canto // 07/03/2013;

// http://forums.adobe.com/thread/1243774?tstart=0

var doc = app.activeDocument;

var sel = doc.selection;

var rename = prompt("Enter the name and ONE character suffix (comma separated, no space):",

...
Translate
Adobe
Guru ,
Jun 28, 2013 Jun 28, 2013

Script has NO access to which layers you have selected in the layers palette…

Translate
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 ,
Jun 28, 2013 Jun 28, 2013

What about the sub-layers then?

This script does what I need but for numbers only.

var doc = app.activeDocument,

    sel = doc.selection,

    rename = prompt("Enter the name:",""),

    done = 0;

if(sel.length>0){

  var nr=rename.match(/\[\w+\]/);

  if(nr){ nr=nr[0].match(/\w+/)[0];

  }

  for(var z=0;z<sel.length;z++){   

    if(nr){

        theRenaming=rename.replace(/\[\w+\]/,nr);

        sel.name = theRenaming;

        nr++;

    } else

      sel.name = rename

  }

} else

  alert("Nothing was selected")

Translate
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 02, 2013 Jul 02, 2013

Ok, I've managed to rename the layers based on selection but I've encountered another problem.

If I select 4 layers for example and run the script starting from letter "A"..it goes well..it renames the four layers from A to D. My problem now is that if I want to start renaming those 4 layers from letter B or C, it will skip layer 1 (if letter B) or layer 2(if letter C). So basically there should be a way to reset the counter when starting to rename and rename first letter with my specified letter and iterate.

Here is my code so far:

var doc = app.activeDocument,

sel = doc.selection,

rename = prompt("Enter the name:","");

done = 0;

var str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

var r = /\[\w+\]/i;

var matching = rename.match( r );

var letter = str.search( matching );

if (letter>=0)

{

   for(i=letter; i<sel.length;i++)

   {

        var nextChar = str.charAt(i);

      if(nextChar){

            theRenaming=rename.replace(/\[\w+\]/, nextChar);

            sel.name = theRenaming;

            letter++;

        }

        else

        sel.name = rename;

   }   

} else

{

alert("Nothing Found!");

}

Any help would be appreciated.

I still don't know why muppet mark said that you cannot access layer names.

Translate
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 03, 2013 Jul 03, 2013
LATEST

so, what you wanted is to rename Selected Objects, not Layers, right?

check this script, I took a different route, I added a couple of comments, if you have any trouble with it, feel free to ask

// this script Renames selected Objects with a base name plus an incremental suffix

// Carlos Canto // 07/03/2013;

// http://forums.adobe.com/thread/1243774?tstart=0

var doc = app.activeDocument;

var sel = doc.selection;

var rename = prompt("Enter the name and ONE character suffix (comma separated, no space):","test,A", "Increment Rename Selected Objects");

if (rename!=null) {// quit if pressed Cancel

    var nameArray = rename.split(",");

    var base = nameArray[0];

    var suffix = nameArray[1];

    var charCode = suffix.charCodeAt (); // convert the suffix character to Unicode

    if(sel.length>0){

        for(var z=0;z<sel.length;z++) {  

            var suffix = String.fromCharCode (charCode+z); // increase the Unicode value and convert it back to a String

            sel.name = base + suffix;

        }

    // Illustrator bug? new names don't update in the UI, this will force the layer panel to redraw

    sel[0].selected = false;

    sel[0].selected = true;

    }

    else

      alert("Nothing was selected");

}

else alert("Cancelled by User");

Translate
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