Copy link to clipboard
Copied
So, I have been spoiled by an After Effects plugin called AE Global Renamer (AEGR) and was wondering if Illustrator had a plug in or script that could do something similar. The beauty of AEGR is that it allows you to search a consistent variable and replace it globally (please check out the example below):
I’ve search the threads and the closest thing I’ve found was a cool plugin by Qwertyfly...​ that allows you to batch rename artboards. Though, the script is restricted to artboards (it would be great if it could rename layers) and doesn’t really have a search/replace option (or I'm not using it correctly):
https://forums.adobe.com/message/7625415#7625415
If any of you know of something that can Batch Rename Layers/Artboards with a search/replace function that would be great!
Thanks!
Will
Message was edited by: Will N
1 Correct answer
here's a script to rename layer names
// findReplaceLayers.jsx
// carlos canto
// https://forums.adobe.com/thread/2391868
function main () {
var idoc, search_string, replace_string, layers, i, tframe, new_string, counter=0;
var idoc = app.activeDocument;
var search_string = Window.prompt ('Enter Search string', 'text 1', 'Find/Replace Layer Names');
if (search_string == null) {
alert ('Cancelled by user');
return;
}
var replace_string = Windo
...
Explore related tutorials & articles
Copy link to clipboard
Copied
I have created a custom script to rename Photoshop layers automatically, you can find it here: http://www.sosfactory.com/batch-rename-photoshop-layers/
Copy link to clipboard
Copied
here's a script to rename layer names
// findReplaceLayers.jsx
// carlos canto
// https://forums.adobe.com/thread/2391868
function main () {
var idoc, search_string, replace_string, layers, i, tframe, new_string, counter=0;
var idoc = app.activeDocument;
var search_string = Window.prompt ('Enter Search string', 'text 1', 'Find/Replace Layer Names');
if (search_string == null) {
alert ('Cancelled by user');
return;
}
var replace_string = Window.prompt ('Enter Replace string', 'text 2', 'Find/Replace Layer Names');
if (replace_string == null) {
alert ('Cancelled by user');
return;
}
layers = idoc.layers;
for (i = 0 ; i < layers.length; i++) {
ilayer = layers[i];
new_string = ilayer.name.replace(search_string, replace_string);
if (new_string != ilayer.name) {
ilayer.name = new_string;
counter++;
}
}
alert(counter + ' changes were made');
}
main();
[11/27/19 - re uploaded the script after migrating to new forum][Carlos]
Copy link to clipboard
Copied
Hi Carlos,
should your script work with CC19? I got an error 1302 ...
Just to be sure I copy-paste your code to text file and saved as .js (tried .jsx as well) and imported via Cmd+F12, if that is corect way. I tried to rename primarily sublayers - grouped two objects "<Group>", but didn't work on regular layers (Layer 1, Layer 2, ...) as well.
Copy link to clipboard
Copied
I wsn'table to make your script work in Illustrator.
Copy link to clipboard
Copied
Just great! Thanks!
Lottie and Rive animation for your web or mobile project.
Copy link to clipboard
Copied
Hi mond, the new forum format messed with the script, I just re uploaded it. Please replace your old script. However, this script's purpose is to rename Layers, not pageItems ie Groups
Copy link to clipboard
Copied
Thank you for quick response and update. Works 🙂 Sadly for me I ended up with manual renaming of 200 <Groups>. Because I could place Layer under Layer (to create sublayer) I thought -probably script doesn't care if it's layer or ect ... just an item in a list (structure).
BTW Seems to me more versatile (universal) if there would be a way to let script rename already selected any kind of items in layer panel (list) and be able to rename what ever (with what ever name) from the list to some name (instead of search for specific part of text in name only). Also for batch rename action people often look for ability of sequential numbering (ascending/descending).
I'm not asking for that, but probably it can touch bigger audience.
Because of my needs ... I searched cross a net with many old not functional scripts (tried on Layers too) that try to cover batch rename, so I'm quite surprised there doesn't exist any (discoverable) working script or made by Adobe yet ...
Copy link to clipboard
Copied
Hi Carlos,
I just tried your script and got this error.
Copy link to clipboard
Copied
Try this one:
// You can change these settings:
var settings = {
// Should the script guess the name for unnamed items like <Group>, <Path>, etc:
replaceGenerics: true,
// Should the script replace "HELLO" when findText is "Hello":
caseSensitive: false
}
// What to find:
var findText = 'layer'
//
// What to replace it with:
var replaceText = 'Hello world'
/**
*
* Don't edit below unless you know what you're doing
*
*/
Array.prototype.forEach = function (callback) {
for (var i = 0; i < this.length; i++) callback(this[i], i, this);
};
function get(type, parent) {
if (arguments.length == 1 || !parent) parent = app.activeDocument;
var result = [];
if (!parent[type]) return [];
for (var i = 0; i < parent[type].length; i++) {
result.push(parent[type][i]);
if (parent[type][i][type])
result = [].concat(result, get(type, parent[type][i]));
}
return result || [];
}
function findReplace(find, replace, options) {
var layers = get('layers');
var pageItems = get('pageItems');
var list = [].concat(layers, pageItems);
var findRX = new RegExp(getEscapedRXString(find), !options.caseSensitive ? 'i' : null)
list.forEach(function (item) {
if (item.name.length)
item.name = item.name.replace(findRX, replace)
else
item.name = options.replaceGenerics && findRX.test(item.typename)
? item.typename.replace(/item/i, '').replace(findRX, replace)
: item.name
})
}
function getEscapedRXString(string) {
return string.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&');
}
findReplace(findText, replaceText, settings)
It should handle any layer or group of any depth no matter how they're nested. It can't affect "<Rectangle>" or "<Ellipse>" because those are typenamed PageItems but otherwise solves for what every one wanted above.
Copy link to clipboard
Copied
The code works well. Could you check if we can search a first string "AB CD" and replace a whole layer name.
For examples:
Layer: AB CD DEFGH = _D_
Layer: AB CD 4ADF68 = _D_
Layer: AB CD 4AKLDA = _D_
Layer: AB CD 56K89A = _D_
...
Copy link to clipboard
Copied
Hi robbie, you need to save the file as plain text instead of RTF.
Copy link to clipboard
Copied
Hi Carlos,
I just tried your script and got this error.
By robbytrione
More on correctly saving and intalling scripts here:
https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html
Copy link to clipboard
Copied
I adapted this script to work for artboards as well as layers by simply doing a 'find and replace' function in text edit to replace 'layers' with 'artboards'.
Simply copy and paste the below under the '------------' into a plain text document (.txt rather than the default .rtf) in text edit and save with the suffix '.jsx' so for example: findAndReplaceArtboards.jsx
To use for layers do a find and replace in text edit for 'artboards' and replace with 'layers' and select all, and then save with an alternative file name such as findAndReplaceLayers.jsx
In Illustrator go to File > Scripts > Other Scripts and navigate to the relevant .jsx document you just saved. You will tehn be prompted to enter the original text that appears on the layers/artboards that you wish to replace, and then you will be prompted to enter the text you wish to replace it with. The script will then run and tell you how many replacements were made.
------------
// findReplaceartboards.jsx
// carlos canto
// https://forums.adobe.com/thread/2391868
function main() {
var counter = 0;
var search_string = Window.prompt('Enter Search string', 'text 1', 'Find/Replace artboard Names');
if (search_string == null) {
alert('Cancelled by user');
return;
}
var replace_string = Window.prompt('Enter Replace string', 'text 2', 'Find/Replace artboard Names');
if (replace_string == null) {
alert('Cancelled by user');
return;
}
var replaceName = function (artboard) {
var name = artboard.name.replace(new RegExp(search_string), replace_string);
if (name !== artboard.name) {
artboard.name = name;
counter++;
}
};
var traverseartboards = function (artboards, action) {
if (artboards) {
for (var i = 0, len = artboards.length; i < len; i++) {
traverseartboards(artboards[i].pageItems, action);
action(artboards[i]);
}
}
};
traverseartboards(app.activeDocument.artboards, replaceName);
alert(counter + ' changes were made');
}
main();
Copy link to clipboard
Copied
Hi everibody,
Is there a way to make that script work on Photoshop? (The prompts apeared but nothing changed).
Also, can the script be used to change just part of the artboard's name?
Ex.: I have 30 artboards name like "project9393_1080x1080px", so every new project needs the "9393" part renamed/updated, for all the 30 artboards, a script to do that would be amazing!
Copy link to clipboard
Copied
Hi Rodrigo, no, unfortunatelly Illustrator scripts don't work in Photoshop.
Copy link to clipboard
Copied
Hello @Rodrigo225252887pkw,
Post your question\request in the Photoshop forum and I will post a script that will rename the artboards for your exact situation.
Regards,
Mike
Copy link to clipboard
Copied
@Mike Bro – Thank you for offering!
@Rodrigo225252887pkw – Perhaps this script will do in the short term:
https://github.com/Paul-Riggott/PS-Scripts/blob/master/Layer%20Name%20Edit.jsx
P.S. If you are reusing the previous template, that reused the previous template etc. then you may have a lot of photoshop:DocumentAncestors metadata adding up, bloating the size of the PSD and potentially in the saved assets as well.
https://prepression.blogspot.com/2017/06/metadata-bloat-photoshopdocumentancestors.html
Copy link to clipboard
Copied
Hi, @Stephen Marsh ! The script worked like a charm! Thank you!
One weird thing: the window didn't get the darkmode on macOS Monterey
Copy link to clipboard
Copied
The script was written before such a thing existed!
You need to change the R/G/B values in the following line to something darker, such as 0.2:
var myBrush = g.newBrush(g.BrushType.SOLID_COLOR, [0.2, 0.2, 0.2, 1]);
EDIT: Or perhaps better -
var myBrush = g.newBrush(g.BrushType.THEME_COLOR, "appDialogBackground");
Copy link to clipboard
Copied
Perfection!
 
Thank you so much!
Copy link to clipboard
Copied
Hi,
I'm trying to rename the artboards instead of layers, would you please help how to rewrite the scripts?
Thanks
Copy link to clipboard
Copied
iampurple wrote:
Hi,
I'm trying to rename the artboards instead of layers, would you please help how to rewrite the scripts?
Thanks
Illustrator artboards? This is the Illustrator forum after all... There was adapted code posted to rename Illustrator artboards earlier in the thread.
Or Photoshop artboards, as this topic thread branched into Photoshop? I'm pretty sure that the same Photoshop code can be used to rename both layers and sets/groups.
Copy link to clipboard
Copied
Hi Stephen,
No, Photoshop artboards. I found there is a script for rename layers, but not for artboard. Would it possible to replace "Layers" to "Artboard" work? Thanks
Copy link to clipboard
Copied
I'm going from memory, but the same (Photoshop) code should rename selected layers or sets/groups.
-
- 1
- 2