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