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
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
...
Copy link to clipboard
Copied
I'm just starting to learn JS, I copied the code above and tried it in Photoshop and only worked for layers rename, not for artboard. I tried to replace the selected layers to artboard in JS and not working. Would you guide how to re-write script that work for artboard rename? Thanks
Copy link to clipboard
Copied
Carlos already said Illy scripts won't work in PS - ask on the PS forum for help.
Copy link to clipboard
Copied
Thanks!
I did use the layers script above and loaded it in Photoshop and it worked though.
Copy link to clipboard
Copied
@Stephen_A_Marsh Stephen, I just wanted to give you a big thanks. I read through this thread and needed something for Photoshop as well. Copied the script and was up and running without a single issue. I really appreciated people who take the time to help the community!
Copy link to clipboard
Copied
@RRowe - You're welcome!
Copy link to clipboard
Copied
I really wanted to export all of the names to a file, edit the file, then import that file again. After not getting that to work, I found this.
I know very little about Illustrator scripting yet, and made a Dumb mistake. I accidentally copied the "--------------" as well. That wasn't in code block formatted text, so I didn't catch it. And rather than giving me errors about the first line, it tols me main(); did something illegal. I have other scripts that didn't define the whole thing as a function and then run it, so I removed that. Then it told me var counter was illegal. What the hell? Since no one was commenting about it not working I took another look and realized my first line was ------------
So to folks wanting this and Also finding Adobe's error system to be mostly useless, be sure Not to accidentally copy extra characters. I guess Adobe just goes ahead and uses them somehow and gives you an error about something Else.
Copy link to clipboard
Copied
Of course, after I had a moment to look at the code that Bing spit out at me I found the mistake.
Rather than just asking for artboard.name it tried to define a variable for it, then use that. Sure, that's fairly standard. But it had this in the code:
var name = artboard.name;
artboardNames.push(name);
The text file it gave me was the correct number of artboards, so I knew Part of it worked, but every text entry was just "Adobe Illustrator"
So I looked back through the code. I didn't get any errors. I don't know much about illustrator scripting yet, but I was guessing that "name" might be something reserved for a global variable. It sure would be nice if it gave an error to that effect. This has been my frustration with attempting to learn any programming language because it's not the language part that is difficult. It's trying to tie the language with Illustrator, or Blender, or Windows, etc.
Anyway, here's the code that works.
Run it (you can drag and drop the file onto illustrator for those who may not know) and it will save a text file on your desktop of all of the artboard names in order.
Do some find and replace, whatever you need. Save that text file, then come back to illustrator and press the button that asks if you want to update the names. And the artboard names get updated to whatever you changed them to.
Keep in mind, I am not a programmer, and I did not write this. Artificial (not quite so) Intelligence finding a bunch of bits and pieces of script and smashing it together. So if you do something silly, like add a line return then it will fail. I see it Was nice enough to think of that potential error and is supposed to give an error instead of changing the names. But I didn't test that out. I just read through it. It looked correct. I saved a copy of the file I was working on, tried it, and it worked.
So use at your own risk.
// This script will export all of the artboard names in order, which can be edited in a text editor, then use that text file to update the artboard names in the file.
// Define the file name and path for the text file
var fileName = "artboard_names.txt";
var filePath = Folder.desktop + "/" + fileName;
// Get the document and the number of artboards
var doc = app.activeDocument;
var numArtboards = doc.artboards.length;
// Create an array to store the artboard names
var artboardNames = [];
// Loop through the artboards and push their names to the array
for (var i = 0; i < numArtboards; i++) {
var artboard = doc.artboards[i];
artboardNames.push(artboard.name);
}
// Write the array to the text file, separated by newlines
var file = new File(filePath);
file.open("w");
file.write(artboardNames.join("\n"));
file.close();
// Display a message that the file has been created
alert("The file " + fileName + " has been created on your desktop. You can edit it in a text editor and then run this script again to update the artboard names.");
// Ask the user if they want to update the artboard names from the text file
var answer = confirm("Do you want to update the artboard names from the text file?");
// If yes, read the text file and update the artboard names
if (answer) {
// Open the text file and read its contents
var file = new File(filePath);
file.open("r");
var contents = file.read();
file.close();
// Split the contents by newlines and store them in an array
var newNames = contents.split("\n");
// Check if the number of new names matches the number of artboards
if (newNames.length == numArtboards) {
// Loop through the artboards and update their names from the array
for (var i = 0; i < numArtboards; i++) {
var artboard = doc.artboards[i];
var newName = newNames[i];
artboard.name = newName;
}
// Display a message that the artboard names have been updated
alert("The artboard names have been updated from the text file.");
} else {
// Display a message that the number of new names does not match the number of artboards
alert("The number of new names in the text file does not match the number of artboards. Please make sure they are equal and try again.");
}
}
Copy link to clipboard
Copied
Hi @JRichardson , this is super useful. Did you encounter a way to find-replace only a selected set of artboards? I have been trying with Batch Renamer, it allows selection of artboards for prefixing and suffixing but not for find-replace. https://github.com/creold/illustrator-scripts/blob/master/jsx/BatchRenamer.jsx