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!
Copy link to clipboard
Copied
Try setting your playback options from actions flyout menu to pause for 1 second, does that help?
Copy link to clipboard
Copied
Unfortunately, this is a bug that has been there for decades.
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 🙂
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();
Copy link to clipboard
Copied
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:
Don't worry, I think it's a good thing you tried to mention the credits. And I hope Williams supplement helps you further.
Copy link to clipboard
Copied
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!