Skip to main content
Inspiring
April 6, 2021
Answered

Help with Script to Rename Selected Paths, not Layers

  • April 6, 2021
  • 1 reply
  • 648 views

Hi,

I have a need to rename selected paths with script. Specifically, I have a path (named or without name) that I need to rename  adding the suffix "+score" to the end.  So, if it is named "object", the script would rename it to "object+score".  I want to be able to select the objects I need to rename and then run the script to only changed the selected objects/paths. 

 

After reading a bunch of past posts, I have been trying for hours without success.  This was similar to a sample script I tried and not error, but nothing happens. Any help would be appreciated.  

#target Illustrator

var doc = activeDocument;
var sel = doc.selection;
var suffix="+score";

for (var i=0; i < sel.length; i++)
     sel.name = sel.name + suffix;

 I am not a scripter. I just piece together scripts until I can get them to work for me.  Thanks in advance! 

This topic has been closed for replies.
Correct answer pixxxelschubser

You forgot the counter:

 

{sel[i].name = sel[i].name + suffix;}

 

 

One problem remains, however: an unnamed item only has a placeholder name. The name itself is blank. An option would be:

 

{sel[i].name = (sel[i].name == "") ? sel[i].typename+suffix : sel[i].name+suffix;}

 

1 reply

pixxxelschubser
Community Expert
pixxxelschubserCommunity ExpertCorrect answer
Community Expert
April 6, 2021

You forgot the counter:

 

{sel[i].name = sel[i].name + suffix;}

 

 

One problem remains, however: an unnamed item only has a placeholder name. The name itself is blank. An option would be:

 

{sel[i].name = (sel[i].name == "") ? sel[i].typename+suffix : sel[i].name+suffix;}

 

cutty3dAuthor
Inspiring
April 6, 2021

@pixxxelschubser, thank you so much!  You have no idea.   

Actually, I added the counter and that worked.  It is working thus far with named and unnamed items with placeholder names.  I will continue testing.