0 Replies Latest reply on Mar 23, 2016 8:52 AM by pav55

    get first result from each page by findGrep

    pav55 Level 1


      I tried to find a solution or a way to solve my problem but without success.

      What I'm trying to do is build an array with findGrep results (what i got done), but want to push to array only first findGrep .contents found from each page.

      If anyone could help me will be great.


      var myDoc = app.activeDocument;
      var myFinds=[];
      var myTempStyle = myDoc.paragraphStyles.item("myNamesTempStyle");
      app.findGrepPreferences = NothingEnum.NOTHING;
      app.changeGrepPreferences = NothingEnum.NOTHING;
      // Set the find options
      app.findChangeGrepOptions.includeFootnotes = false;
      app.findChangeGrepOptions.includeHiddenLayers = false;
      app.findChangeGrepOptions.includeLockedLayersForFind = true;
      app.findChangeGrepOptions.includeLockedStoriesForFind = true;
      app.findChangeGrepOptions.includeMasterPages = false;
      // Regular expression for finding an email address
      app.findGrepPreferences.findWhat = "my sample text";
      // Apply the change to 24-point text only
      //app.findGrepPreferences.pointSize = 24;
      app.changeGrepPreferences.appliedParagraphStyle = myTempStyle;
      // Perform the operation
      // Clear the find/change preferences after the search
      app.findGrepPreferences = NothingEnum.NOTHING;
      app.changeGrepPreferences = NothingEnum.NOTHING;
      app.findGrepPreferences = null;
      app.findGrepPreferences.appliedParagraphStyle = "myNamesTempStyle";
      result = app.activeDocument.findGrep(true);
      while (result.length){
      app.findGrepPreferences = NothingEnum.nothing;
      app.findGrepPreferences = NothingEnum.nothing;
      app.findGrepPreferences.findWhat =str.contents;
      var myFind  = myDoc.findGrep();
      var a = myFind.length-1;


      will attach indd file with sample copy but don't know how I can attach file here so you can use this one:



      Uda aut dus prorestiam, officit aturectotate

      quo blabor suntia se volut quid 1b

      ulpa iducidel is esequidi ommolup iduciis sam, sunt evellaccusa consenit, ut eaturibus minimus experero quam, ute vendicidebit maximus porem ipiduci lligentum rerum vellacc atquiae nonsequ ostorro ipsa nimil min por solorepro conesse



      info about case I'm working with indd file and above copy:

      paragraph style attached to second paragraph, number at the end is usefull to check result I'm working on. in every textframe is different. Text frames and amount of text frames on pages are random. Text frames are mixed - text frames from page 4 swapped with text frames from 2 etc, to mixed application order of text frames.


      I dont need to get "myFind" from first textframe (on page) but I need to limit "myFind" to first founded on page per page


      If you'll have some questions I'm for disposal.

      Thank you