• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Using Find/Replace as part of an action

Explorer ,
Apr 26, 2021 Apr 26, 2021

Copy link to clipboard

Copied

Hi folks,

 

I'm trying to create an action which will replace the text in a box containing the phrase '??????'.

 

When I create the action using the menu item and run it, it works perfectly. However, when I restart Illustrator the action appears to skip the find/replace step entirely.

 

Any ideas on how to address this?

 

Thanks in advance!

TOPICS
Scripting , Type

Views

474

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
Adobe
Community Expert ,
Apr 26, 2021 Apr 26, 2021

Copy link to clipboard

Copied

Try setting your playback options from actions flyout menu to pause for 1 second, does that help?

MikeGondek_0-1619439897660.png

 

Votes

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
Community Expert ,
Apr 26, 2021 Apr 26, 2021

Copy link to clipboard

Copied

Unfortunately, this is a bug that has been there for decades.

 

Votes

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 26, 2021 Apr 26, 2021

Copy link to clipboard

Copied

Thanks for the replies! I found a JS code which I'm using as part of the action instead, and which appears to be working great. Code is below (apologies for not crediting the author, the page seems to have vanished from my history!):

 

function FindAndReplaceScript_AllOpenDocuments(){      
        for(var i=app.documents.length -1; i > -1;  i--){      
        app.documents[i].activate();  
        var aDoc = app.documents[i];  

        var searchString = /OLDTEXT/gi;     
        var replaceString = 'NEWTEXT';       

        var theTF = aDoc.textFrames;      
        if (theTF.length > 0) {      
            for (var j = 0 ; j <theTF.length; j++) {      
                var aTF = theTF[j];      
                var newString = aTF.contents.replace(searchString, replaceString);      
                if (newString != aTF.contents) {      
                    theTF[j].contents = newString;      
                }      
            }      
        }  
    }  
};      
FindAndReplaceScript_AllOpenDocuments(); 

 

Just replace 'OLDTEXT' with 'NEWTEXT'. Worth pointing out, this carries out the script on ALL open documents, although I'm sure someone more experienced with JS can modify it 🙂

Votes

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
Community Expert ,
Apr 26, 2021 Apr 26, 2021

Copy link to clipboard

Copied

here you go. This one will do all open documents, or just the active document. You can choose which one you want to use by toggling the comments on lines 4 and 8.

 

function FindAndReplaceScript()
{
	//to process all open documents
	var filesToProcess = app.documents;

	//to process only active document
	//don't neglect the brackets. this needs to be an array/collection
	// var filesToProcess = [app.activeDocument];


	for (var i = filesToProcess.length - 1; i > -1; i--)
	{
		filesToProcess[i].activate();
		var aDoc = filesToProcess[i];

		var searchString = /OLDTEXT/gi;
		var replaceString = 'NEWTEXT';

		var theTF = aDoc.textFrames;
		if (theTF.length > 0)
		{
			for (var j = 0; j < theTF.length; j++)
			{
				var aTF = theTF[j];
				var newString = aTF.contents.replace(searchString, replaceString);
				if (newString != aTF.contents)
				{
					theTF[j].contents = newString;
				}
			}
		}
	}
};
FindAndReplaceScript();

Votes

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
Community Expert ,
Apr 26, 2021 Apr 26, 2021

Copy link to clipboard

Copied

@mikes82936200 

this code from the first post sounds strangely familiar to me - even though it's garbled.

At that time, I rarely left credits in my codes

😉

 

base code (my code wrapped into a function by @Silly-V )

Find and Replace Script for multiple files

 

more complex with same base code:

Multiple Line Replace Script? 

 

Don't worry, I think it's a good thing you tried to mention the credits. And I hope Williams supplement helps you further.

Votes

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 27, 2021 Apr 27, 2021

Copy link to clipboard

Copied

LATEST

D'oh, sorry @pixxxelschubser!! Belated thanks for your work, helped me so much yesterday and I'll check out the complex code later today.

 

Thanks again!

Votes

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