14 Replies Latest reply on Oct 20, 2016 2:07 AM by cmoke73

    Javascript - Find-Replace with GREP

    cmoke73

      Okay, it is my first Javascript, not true: it´s my second one.

      Working on the first one I figured out how to apply different paragraph-stypes to the paragraphs in a selected text frame.

       

      Now, I actually would like to do the previous step: to search for a particular word and to replace it in special form.

      And, because I am a js-greenhorn, it doesn´t work, of course...

       

      Here the code:

      var doc = app.activeDocument;  
      var Auswahl = app.selection[0];
      var AlleAbsaetze = Auswahl.paragraphs.everyItem();
      
      app.findGrepPreferences = NothingEnum.nothing; // Suchfeld leeren
      app.changeGrepPreferences = NothingEnum.nothing; // Ersetzen-Feld leeren
      // Voreinstellung für das GREP
      app.findChangeGrepOptions.includeFootnotes = true;
      app.findChangeGrepOptions.includeHiddenLayers = false;
      app.findChangeGrepOptions.includeLockedLayersForFind = false;
      app.findChangeGrepOptions.includeLockedStoriesForFind = false;
      app.findChangeGrepOptions.includeMasterPages = false;
      
      
      AlleAbsaetze.findGrepPreferences.findWhat = "Art\.\-Nr\.";
      AlleAbsaetze.changeGrepPreferences.changeTo = "Art\.";
      doc.changeGrep();
      
      app.findGrepPreferences = NothingEnum.nothing; // Suchfeld leeren
      app.changeGrepPreferences = NothingEnum.nothing; // Ersetzen-Feld leeren
      

       

      The engine stops at row 15 and nothing happens.

      I'm sure it's a stupid beginner's mistaker, but I do not know where.

       

      The error-message is: "Object does not support the property or method 'findGrepPreferences'."

      I suppose it´s not possible to assign the GREP-search-function neither to a paragraph nor to a text frame. Isn´t it?

       

      Any idea?