0

I am using ExtendScript with InDesign to have some simple search and replace to change a GREP.

If I write them out one by one everything works fine.

app.findGrepPreferences = app.changeGrepPreferences = null;
app.findChangeGrepOptions = NothingEnum.nothing;
app.findGrepPreferences.findWhat = '^~8 ';
app.changeGrepPreferences.changeTo = `~8\\t`;
myDoc.changeGrep();

But I want to tidy things up and create a loop that runs two arrays containing the search and the find.

var findWhat = [ '^~8 ', '^·( |\\t)', '~S', '^ +', ' +$', '  +', '~P', '^\\t+(?=\\r)', '\\n', '\\r\\r\\r+'];

var changeTo = ['~8\\t','~8\\t',' ', '','',' ','\\r','','\\r','\\r\\r'];

for(var i = 0; i < findWhat.lenght; i++){
    app.findGrepPreferences = app.changeGrepPreferences = null;
    app.findChangeGrepOptions = NothingEnum.nothing;
    app.findGrepPreferences.findWhat = findWhat[i];
    app.changeGrepPreferences.changeTo = changeTo[i];
    myDoc.changeGrep();
}

This doesn't give me an error but it doesn't change anything either. Is there a way to have some kind of error handling of notation set that can provide me with some information?

I'm edditing the code in ExtendScript Toolkit

Interactive
  • 1,474
  • 5
  • 25
  • 57

1 Answers1

1

I found my own embarrassing solution.

The loop doesn't loop because it doesn't understand what lenght means.
Changed it to length and it runs fine......

var findWhat = [ '^~8 ', '^·( |\\t)', '~S', '^ +', ' +$', '  +', '~P', '^\\t+(?=\\r)', '\\n', '\\r\\r\\r+'];

var changeTo = ['~8\\t','~8\\t',' ', '','',' ','\\r','','\\r','\\r\\r'];

for(var i = 0; i < findWhat.length; i++){
    app.findGrepPreferences = app.changeGrepPreferences = null;
    app.findChangeGrepOptions = NothingEnum.nothing;
    app.findGrepPreferences.findWhat = findWhat[i];
    app.changeGrepPreferences.changeTo = changeTo[i];
    myDoc.changeGrep();
}
Interactive
  • 1,474
  • 5
  • 25
  • 57