Can someone share script that renames objects in an layer.

Explorer ,
Apr 14, 2022 Apr 14, 2022

Copy link to clipboard

Copied

I do have objects with different names but common words in the name. I want to be able to use a script to "Find and Replace" words in an randomly named layer. Objects can be 500+ sometimes.

Renaming objects - Start Point.JPG

 

Endgoal Example:

Select all objects in the layer run the script get an pop up like "Find and replace" in Excel, type the old name/s then type the new name/s and the words to be replaced in every selected object.

Renaming objects - End Goal.JPG

TOPICS
Scripting

Views

61

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

Advocate , Apr 15, 2022 Apr 15, 2022
// select items var doc = app.activeDocument; var input1 = prompt('Enter strings separated by comma and space (", ")', "find this, replace with this"); var input2 = input1.split(", "); var find = new RegExp(input2[0], "g", "i"); var replace = input2[1]; for (var i = 0; i < app.selection.length; i++) { app.selection[i].name = app.selection[i].name.replace(find, replace); }

Likes

Translate

Translate
Advocate ,
Apr 15, 2022 Apr 15, 2022

Copy link to clipboard

Copied

// select items
var doc = app.activeDocument;
var input1 = prompt('Enter strings separated by comma and space (", ")', "find this, replace with this");
var input2 = input1.split(", ");
var find = new RegExp(input2[0], "g", "i");
var replace = input2[1];
for (var i = 0; i < app.selection.length; i++) {
    app.selection[i].name = app.selection[i].name.replace(find, replace);
}

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
Explorer ,
Apr 15, 2022 Apr 15, 2022

Copy link to clipboard

Copied

LATEST

It does the job perfectly!

 

Thank you so much! 🙂

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