Help with Script to Rename Selected Paths, not Layers

Community Beginner ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

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! 

TOPICS
Scripting

Views

72

Likes

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

Adobe Community Professional , Apr 06, 2021 Apr 06, 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;}

Likes

Translate

Translate
Adobe Community Professional ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

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;}

 

Likes

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 ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

LATEST

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

 

Likes

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