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

Using app.findGrep() and app.changeGrep() consecutively

Community Beginner ,
Jan 06, 2014 Jan 06, 2014

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: 

  1. Loop through a list of expressions, look for every expression with app.findGrep() and insert Note-Markers at the beginning and at the end of a match. 
  2. Loop through the same list again and find & replace with corresponding terms of another predefined list, using app.changeGrep(). After that, use the positions of the markers to draw rectangles on a new layer in order to visualize the changes. 

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

TOPICS
Scripting
2.0K
Translate
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
Enthusiast ,
Jan 07, 2014 Jan 07, 2014

As I read the theory it should work for you.  If you post your code snippet it will be easier the decipher them.

Translate
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 ,
Jan 08, 2014 Jan 08, 2014
LATEST

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);

Translate
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