Skip to main content
New Participant
October 6, 2017
Answered

Script to Batch Rename Layers/Artboards with Search/Replace Function?

  • October 6, 2017
  • 4 replies
  • 18779 views

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

This topic has been closed for replies.
Correct answer CarlosCanto

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]

4 replies

New Participant
September 9, 2021

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();

Rodrigo225252887pkw
New Participant
January 6, 2022

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!

CarlosCanto
Community Expert
January 6, 2022

Hi Rodrigo, no, unfortunatelly Illustrator scripts don't work in Photoshop.

CarlosCanto
Community Expert
November 27, 2019

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

Participating Frequently
November 28, 2019

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

CarlosCanto
CarlosCantoCorrect answer
Community Expert
September 3, 2018

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]

Participating Frequently
November 27, 2019

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.

New Participant
September 3, 2018

I have created a custom script to rename Photoshop layers automatically, you can find it here: http://www.sosfactory.com/batch-rename-photoshop-layers/