Copy link to clipboard
Copied
I have a script that should find and replace predefined terms and mark the changes visually on a separate layer.
The process basically works in two steps:
The problem is that even though Step 1 works fine (marks show up at their correct positions), step 2 doesn't seem to do anything, unless I change the findWhat parameter to an expression that hasn't been used already in the list of step 1.
So, my guess is that Indesign somehow caches all performed searches and prevents any further look-ups with those expressions.
However, if I use the standard find&replace form after the execution of the script, I can still find any expression from the list without any issues. Can anyone see how I can solve this issue?
Thanks for any help!
Sam
Copy link to clipboard
Copied
As I read the theory it should work for you. If you post your code snippet it will be easier the decipher them.
Copy link to clipboard
Copied
I don't know what is your 'predefined list'.
Look at the following code snippet, the hope can help you:
var mDoc = app.activeDocument, mFind,mChange=0;
//step1
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = '\\d+kg';
mFind=mDoc.findGrep();
//step2
for(var i=0;i<mFind.length;i++) {
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = '\\d+';
app.changeGrepPreferences.changeTo = '$0';
var re=mFind.changeGrep();
mChange+=re.length;
}
app.findGrepPreferences = app.changeGrepPreferences = null;
alert("find:"+mFind.length+",change:"+mChange);
Find more inspiration, events, and resources on the new Adobe Community
Explore Now