10 Replies Latest reply on Jun 14, 2011 11:52 PM by REVA83

    Sort Array of Foundtext as well as respective Page Number


      Hi All,


      I am a novice scripter. Also this is my first Indesign script. Please do help anyone for my first script. Following is my requirement.


      I want to generate a particular character style applied text with belonging "Page Number". Also i need to Sort the found text alphabetically with belonging page number itself. I just generated the text as well as belonging page number by writing the following code.


      var myDoc = app.activeDocument;
      var myDocPath = app.activeDocument.filePath;
      var myDocName = app.activeDocument.name;


      app.findTextPreferences = null;
      app.findTextPreferences.appliedCharacterStyle = myDoc.characterStyles.item("Test");
      var myText = myDoc.findText();
      var myPageNumber = new Array;
      var myFoundText = new Array;
      var myFoundTextSort = new Array;


      for (var i = 0; i < myText.length; i++)
           myFoundText.push (myText[i].contents);


      for (j = 0; j < myText.length; j++)
           var r = getPageFor(myText[j].characters[0]);
           myPageNumber.push ( r.name);


          var inc=0;
          var myLogFile = new File(myDocPath.fsName + "/Text_Report_" + app.activeDocument.name.split(".")[0] +".log");
          if(myLogFile.open("w", undefined, undefined))
                  for (var k=0; k<myFoundText.length; k++)
                      serialno = k+1;
                      myLogFile.writeln("  "+serialno+".  "+myFoundText[k]+" --- Page " +myPageNumber[k]);




      function getPageFor (element)
           while (!(element instanceof Page || element instanceof Application))
                if (element instanceof Character)
                     element = element.parentTextFrames[0].parent;
                     element = element.parent;
           if (element instanceof Page)
                return element;
           return null;



      Please do help anyone. Thanks in advance