Highlighted

Find and replace text across multiple Illustrator files

Community Beginner ,
Apr 27, 2018

Copy link to clipboard

Copied

With the printers now looking for AI or EPS files, I have run into this problem a lot.

Is there a way to find and replace text across multiple Illustrator files like you can do in Indesign & Dreamweaver? It would save me days of double-clicking and pasting.

Please help.

Wayne

Adobe Community Professional
Correct answer by CarlosCanto | Adobe Community Professional

Hi Wayne, here's a script that replaces XXXX with NEW YORK across all open documents. Let me know if you need help changing the script to find something more meaningful.

// findReplace.jsx

// carlos canto

// https://forums.adobe.com/thread/2484457

function main () {

    var idoc, search_string, replace_string, tframes, i, tframe, new_string, counter=0;

    for (var a=0; a<app.documents.length; a++) {

        idoc = app.documents;

        search_string = /xxxx/gi; // g for global search, remove i to make a case sensitive search

        replace_string = "NEW YORK";

      

        tframes = idoc.textFrames;

      

        for (i = 0 ; i < tframes.length; i++) {

            tframe = tframes;

            new_string = tframe.contents.replace(search_string, replace_string);

            if (new_string != tframe.contents) {

                tframe.contents = new_string;

                counter++;

            }

        }

    }

    alert(counter + ' changes were made');

    donate (File($.fileName).displayName);

}

main();

function donate(thisScript) {

    var donateStrPref = 'aiscripts.com/donate/'+thisScript;

    var donated = app.preferences.getStringPreference (donateStrPref);

  

    if (donated != 'true') {

        var showAgain = showDonateWindow ();

        if (showAgain) {

            //alert('checked');

            app.preferences.setStringPreference (donateStrPref, 'true');

        }

    }

}

function showDonateWindow() {

    var win = new Window('dialog', 'https://www.paypal.me/aiscripts');

    var lblDonate = win.add('staticText', undefined, 'Do you find the script valuable?\nDo you use the script commercially?\nPlease consider donating', {multiline:true});

    var grp = win.add('group');

    var btnCancel = grp.add('button', undefined, 'Cancel');

    var btnDonate = grp.add('button', undefined, 'Donate');

    var chk = win.add('checkbox', undefined, "Do not show me this message again");

    btnDonate.onClick = function(){

        openURL( 'www.paypal.me/aiscripts' );

        win.close();

    }

    win.center();

    if(win.show() == 2){

        //alert("Cancelled");

        return null;

    } else {

        return chk.value;

    }

    

    function openURL( address ) {

        var f = File( Folder.desktop + '/aiOpenURL.url' );

        f.open( 'w' );

        f.write( '[InternetShortcut]' + '\r' + 'URL=http://' + address + '\r' );

        f.close();

        f.execute();

        f.remove();

    };

}

Views

3.6K

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

Find and replace text across multiple Illustrator files

Community Beginner ,
Apr 27, 2018

Copy link to clipboard

Copied

With the printers now looking for AI or EPS files, I have run into this problem a lot.

Is there a way to find and replace text across multiple Illustrator files like you can do in Indesign & Dreamweaver? It would save me days of double-clicking and pasting.

Please help.

Wayne

Adobe Community Professional
Correct answer by CarlosCanto | Adobe Community Professional

Hi Wayne, here's a script that replaces XXXX with NEW YORK across all open documents. Let me know if you need help changing the script to find something more meaningful.

// findReplace.jsx

// carlos canto

// https://forums.adobe.com/thread/2484457

function main () {

    var idoc, search_string, replace_string, tframes, i, tframe, new_string, counter=0;

    for (var a=0; a<app.documents.length; a++) {

        idoc = app.documents;

        search_string = /xxxx/gi; // g for global search, remove i to make a case sensitive search

        replace_string = "NEW YORK";

      

        tframes = idoc.textFrames;

      

        for (i = 0 ; i < tframes.length; i++) {

            tframe = tframes;

            new_string = tframe.contents.replace(search_string, replace_string);

            if (new_string != tframe.contents) {

                tframe.contents = new_string;

                counter++;

            }

        }

    }

    alert(counter + ' changes were made');

    donate (File($.fileName).displayName);

}

main();

function donate(thisScript) {

    var donateStrPref = 'aiscripts.com/donate/'+thisScript;

    var donated = app.preferences.getStringPreference (donateStrPref);

  

    if (donated != 'true') {

        var showAgain = showDonateWindow ();

        if (showAgain) {

            //alert('checked');

            app.preferences.setStringPreference (donateStrPref, 'true');

        }

    }

}

function showDonateWindow() {

    var win = new Window('dialog', 'https://www.paypal.me/aiscripts');

    var lblDonate = win.add('staticText', undefined, 'Do you find the script valuable?\nDo you use the script commercially?\nPlease consider donating', {multiline:true});

    var grp = win.add('group');

    var btnCancel = grp.add('button', undefined, 'Cancel');

    var btnDonate = grp.add('button', undefined, 'Donate');

    var chk = win.add('checkbox', undefined, "Do not show me this message again");

    btnDonate.onClick = function(){

        openURL( 'www.paypal.me/aiscripts' );

        win.close();

    }

    win.center();

    if(win.show() == 2){

        //alert("Cancelled");

        return null;

    } else {

        return chk.value;

    }

    

    function openURL( address ) {

        var f = File( Folder.desktop + '/aiOpenURL.url' );

        f.open( 'w' );

        f.write( '[InternetShortcut]' + '\r' + 'URL=http://' + address + '\r' );

        f.close();

        f.execute();

        f.remove();

    };

}

Views

3.6K

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
Adobe Community Professional ,
Apr 29, 2018

Copy link to clipboard

Copied

In older versions of Illustrator that used to work with Batch processing action(s), but I can remember that some users claimed that it doesn't work anymore or not as expected.

Which version of Illustrator are you using? What are you trying to find and replace? Just one single word or various instances of single words? Or something else?

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
Reply
Loading...
Community Beginner ,
May 02, 2018

Copy link to clipboard

Copied

I am running CC2018.

Here is the Scenario. I have 12 eps files with the client logo and the location (live type) underneath. The 12 files are just different brand standard colors.

There are 430 different locations (430X12). Instead of hitting paste 12X430 times, I would like to do find and replace 430 times.

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
Reply
Loading...
Adobe Community Professional ,
May 03, 2018

Copy link to clipboard

Copied

Can you share a sample file (or a couple of sample files)?

Also, is the location always the same (word) inside the 12-packs?

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
Reply
Loading...
Adobe Community Professional ,
May 03, 2018

Copy link to clipboard

Copied

InDesign is great about Find & Replace function.

Even now, this function in Macromedia FreeHand MX is still stronger than Illustrator.

This function of Illustrator has to be improved.

Include InDesign document for colors and make these changes with "Ink Alias" function.

Graphic Designer Educator / PrePress Consultant

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
Reply
Loading...
Adobe Community Professional ,
May 03, 2018

Copy link to clipboard

Copied

Thanks for adding refreshing thoughts to this topic, Ceyhun.

But may I ask you what it has to do with the initial request?

(InDesign's Ink Alias?)

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
Reply
Loading...
Adobe Community Professional ,
May 03, 2018

Copy link to clipboard

Copied

The Ink Alias ​​function provides ease of gathering the colors contained in the document under the specified spot colors. Photoshop lets you change colors from Illustrator documents without changing the original.

Graphic Designer Educator / PrePress Consultant

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
Reply
Loading...
Adobe Community Professional ,
May 03, 2018

Copy link to clipboard

Copied

Yes, but this is completely unrelated to this thread.

Please reread Wayne's initial request.

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
Reply
Loading...
Adobe Community Professional ,
May 03, 2018

Copy link to clipboard

Copied

You're right. The Find Multiple Documents function took me directly to InDesign.

Graphic Designer Educator / PrePress Consultant

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
Reply
Loading...
Community Beginner ,
May 04, 2018

Copy link to clipboard

Copied

Below is a link to an example folder. I have to replace the XXXX with New York City in all 8 EPS files.

Then repeat that for about 400 locations.

WeTransfer

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
Reply
Loading...
Adobe Community Professional ,
May 06, 2018

Copy link to clipboard

Copied

Hi Wayne, here's a script that replaces XXXX with NEW YORK across all open documents. Let me know if you need help changing the script to find something more meaningful.

// findReplace.jsx

// carlos canto

// https://forums.adobe.com/thread/2484457

function main () {

    var idoc, search_string, replace_string, tframes, i, tframe, new_string, counter=0;

    for (var a=0; a<app.documents.length; a++) {

        idoc = app.documents;

        search_string = /xxxx/gi; // g for global search, remove i to make a case sensitive search

        replace_string = "NEW YORK";

      

        tframes = idoc.textFrames;

      

        for (i = 0 ; i < tframes.length; i++) {

            tframe = tframes;

            new_string = tframe.contents.replace(search_string, replace_string);

            if (new_string != tframe.contents) {

                tframe.contents = new_string;

                counter++;

            }

        }

    }

    alert(counter + ' changes were made');

    donate (File($.fileName).displayName);

}

main();

function donate(thisScript) {

    var donateStrPref = 'aiscripts.com/donate/'+thisScript;

    var donated = app.preferences.getStringPreference (donateStrPref);

  

    if (donated != 'true') {

        var showAgain = showDonateWindow ();

        if (showAgain) {

            //alert('checked');

            app.preferences.setStringPreference (donateStrPref, 'true');

        }

    }

}

function showDonateWindow() {

    var win = new Window('dialog', 'https://www.paypal.me/aiscripts');

    var lblDonate = win.add('staticText', undefined, 'Do you find the script valuable?\nDo you use the script commercially?\nPlease consider donating', {multiline:true});

    var grp = win.add('group');

    var btnCancel = grp.add('button', undefined, 'Cancel');

    var btnDonate = grp.add('button', undefined, 'Donate');

    var chk = win.add('checkbox', undefined, "Do not show me this message again");

    btnDonate.onClick = function(){

        openURL( 'www.paypal.me/aiscripts' );

        win.close();

    }

    win.center();

    if(win.show() == 2){

        //alert("Cancelled");

        return null;

    } else {

        return chk.value;

    }

    

    function openURL( address ) {

        var f = File( Folder.desktop + '/aiOpenURL.url' );

        f.open( 'w' );

        f.write( '[InternetShortcut]' + '\r' + 'URL=http://' + address + '\r' );

        f.close();

        f.execute();

        f.remove();

    };

}

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
Reply
Loading...
Adobe Community Professional ,
May 06, 2018

Copy link to clipboard

Copied

This could also be done with actions in Batch mode, but as you are probably dealing with 400 different locations you could only process 8 files at once.

In case you are going to set up similar files in the future, I'd recommend to take a look at Illustrator's text variables (see Variables palette).

Moreover, there are applications that can find and replace across multiple files in one whack, but in my experience they do not work very well with the .eps file format.

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
Reply
Loading...
New Here ,
May 23, 2018

Copy link to clipboard

Copied

Hey Carlos,

This seems to work well.

Any chance you could make it work with multiple text entries and replaces?

Thanks!

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
Reply
Loading...
Adobe Community Professional ,
Jun 08, 2018

Copy link to clipboard

Copied

Hi a.melv, it seems possible. Can you share more details about your needs?

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
Reply
Loading...
New Here ,
Jun 08, 2018

Copy link to clipboard

Copied

Hey Carlos,

It's all good. The deadline has past anyhow.

Thanks!

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
Reply
Loading...
New Here ,
Sep 20, 2018

Copy link to clipboard

Copied

Hey Carlos,

I think I have a similar issue. would you be willing to help?

I'm basically just trying to change multiple.ai files they all have a text box that says "Fall 2018" and I want them all to change to "Winter 2018".

However, I also need to figure out how to change the font size of "Winter" so that it will fit in a text box, as well as change a layer title from "F18" to "W18".

Do you know an efficient way of doing this rather than just going into 200 files and manually changing them?

Any help is appreciated. Thank you!

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
Reply
Loading...
Contributor ,
Jan 17, 2019

Copy link to clipboard

Copied

Carlos, this script has really changed my workflow! What would you suggest to do multiple search queries at once? I tried creating more variables and adding to the for loop, but it wasn't working properly...I'm not sure if I'm getting syntax wrong or what.

I've tried just creating additional search and replace variables as well as an additional new_string variable. That just ran the second query, so I created new tframe and tframes variables and had the same result with the second one running...

// findReplace.jsx

// carlos canto

// https://forums.adobe.com/thread/2484457

function main () {

    var idoc, search_string, replace_string, search_string1, replace_string1, tframes, tframes1, i, tframe, tframe1, new_string, new_string1=0;

    for (var a=0; a<app.documents.length; a++) {

        idoc = app.documents;

        search_string = /\d+\/\d+\/(18|19)/gi; // g for global search, remove i to make a case sensitive search

        replace_string = "01/30/19";

        search_string1 = /(REV) \dv\d+/gi; // g for global search, remove i to make a case sensitive search

        replace_string1 = "$1 4v0";

        tframes = idoc.textFrames;

        tframes1 = idoc.textFrames;

        for (i = 0 ; i < tframes.length; i++) {

            tframe = tframes;

            tframe1 = tframes;

            new_string = tframe.contents.replace(search_string, replace_string);

            new_string1 = tframe1.contents.replace(search_string1, replace_string1);

            if (new_string != tframe.contents) {

            tframe.contents = new_string;

            }

            if (new_string1 != tframe1.contents) {

            tframe1.contents = new_string1;

            }

        }

    }

}

main();

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
Reply
Loading...
New Here ,
May 17, 2019

Copy link to clipboard

Copied

Hello Wayne and all pal,  may I ask what is the exact step to copy the above script/code, and successfully run it to multiple opened AI file? Why it seemed all knows the step how to copy/save this code to what format, and open/import it in or with what?     Assuming I have zero knowledge in script/code.

Do I have to save it as Applescript of .jsx file?  which function/feature in Illustrator can import or run these code?

MAY I ASK THE EXACT STEPS TO RUN THIS CODE:
1). starting from copying it via web browser;
2). change xxxxxx in script to the needed find text-string;
3).  replace "NEW YORK" in script to the needed replace text-string;
4). open ???? application, and paste these code into ????,  save in ????? format;
5). open Adobe Illustrator cc, and the multiple AI files;
6).  then....what?

THANKS 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
Reply
Loading...
New Here ,
May 17, 2019

Copy link to clipboard

Copied

Hello Wayne,  I just googled how to run script in AI. And it did work! I"ll make appropriate donation to your Paypal. Thanks!  (the only one thing I wanna share is that, if I copy/paste the code to text editor, and save as .jsx file, it doesn't work.  I have to duplicate one of AI's default .jsx file, and replace the text, that works!

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
Reply
Loading...
Adobe Community Professional ,
May 17, 2019

Copy link to clipboard

Copied

glau30624370  schrieb

if I copy/paste the code to text editor, and save as .jsx file, it doesn't work.  I have to duplicate one of AI's default .jsx file, and replace the text, that works!

The text editor needs to set up to make TXT files.

By default many text editors are set to make RTF.

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
Reply
Loading...
Community Beginner ,
Sep 17, 2019

Copy link to clipboard

Copied

Hi, Carlos. This script doesn't seem to work in Illustrator CC 2019. It doesn't get past Line 11. I get: Error 1302: No such element / Line 11: / -> tframes = idoc.textFrames; Is there a fix for this code to make it run under Illustrator CC 2019?

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
Reply
Loading...
New Here ,
Apr 04, 2020

Copy link to clipboard

Copied

Hi Carlos!
The Scipt could be really useful for me.

Might it be possible to have something like a search & replace dialog instead of the necesitty to change the code?

This would be fantastic!

While doing a search & replace on documents with a large amount of text boxes it seems like illustrator crashes but mostly it doesn't - it's only not responding. I guess thats because the script needs to go through all text boxes in all open documents.

So something like a progress bar would also be very useful.

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
Reply
Loading...
Adobe Community Professional ,
Apr 04, 2020

Copy link to clipboard

Copied

here you go, I added a prompt to enter search/replace strings. You're correct, if you have a lot of text, Illustrator will freeze but it's still working on the background. Just wait for the scrip to finish. I'll add a progress bar when I have more free time.

 

// findReplace v4.jsx
// carlos canto
// https://forums.adobe.com/thread/2484457

function main () {
    var idoc, search_string, replace_string, tframes, i, tframe, new_string, counter=0;
    
    search_string = Window.prompt ('Enter Search string', 'search string', 'Find/Replace Across All Open Documents');
    
    if (search_string == null) {
        alert ('Cancelled by user');
        return;
    }

    replace_string = Window.prompt ('Enter Replace string', 'replace string', 'Find/Replace Across All Open Documents');
    
    if (replace_string == null) {
        alert ('Cancelled by user');
        return;
    }

    for (var a=0; a<app.documents.length; a++) {
        idoc = app.documents[a];
         
        tframes = idoc.textFrames;
         
        for (i = 0 ; i < tframes.length; i++) {
            tframe = tframes[i];
            new_string = tframe.contents.replace(new RegExp(search_string, 'g'), replace_string);
            
            if (new_string != tframe.contents) {
                tframe.contents = new_string;
                counter++;
            }
        }
    }
    alert(counter + ' changes were made');
}

main();

 

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
Reply
Loading...
New Here ,
Apr 05, 2020

Copy link to clipboard

Copied

Thank you very much Carlos!

This is fantatstic.

Do you know, which GREP commands work with Illustrator?

I just tried the full stop which works like expected, also with the plus modifier.

For troubleshooting i tried to wrap your script into an undo functionality like it has been described here:
https://indesignsecrets.com/add-undo-to-your-script.php
but this only seems to work with InDesign scripts.

Thank you very much & stay healthy!

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