3 Replies Latest reply on Jun 10, 2009 1:24 PM by KeithGilbert

    [JS CS3] Trouble with changeGrep() array

    KeithGilbert Level 1

      This is strange, or else I'm totally missing something simple:


      My script does a GREP search for a text string in a table, and assigns a paragraph style to the string. Next, for each string that was found, I want to merge the cell that contains the string with the two cells directly to the right of the cell. The line


      var myFound = mySelection.changeGrep();


      does the changing of the text string.


      I understand that changeGrep() returns an array, in this case, of insertion points. When I run the script on a table that contains 5 instances of the string that the Grep search is looking for, myFound returns an array of 5 insertion points like I'd expect. Except that if I pause the script and examine the contents of the array, this is what I get:


      myFound[0].parent.contents displays the correct (first) text string that was changed

      myFound[1].parent.contents isn't correct. It displays the contents of the cell directly to the left of he text string that was changed.

      myFound[2] through myFound[4] are also incorrect.


      Again, this is examining the array before I do anything to the table such as merging cells, etc.


      So, why doesn't the array return the correct insertion points?


      Here is the full script function:



      function myProcessTable(mySelection) {

      // Specify the column width

      mySelection.columns.item(0).width = 68;

      mySelection.columns.item(1).width = 103.5;

      mySelection.columns.item(2).width = 24;

      mySelection.columns.item(3).width = 16;

      mySelection.columns.item(4).width = 16;

      mySelection.columns.item(5).width = 16;

      // Find every occurance of ddd.dd/d in the current table, and apply the Table body, cond, center paragraph style,

      app.findGrepPreferences = NothingEnum.nothing;

      app.changeGrepPreferences = NothingEnum.nothing;

      app.findGrepPreferences.findWhat = "\\d.\\d\\d/\\d";

      app.changeGrepPreferences.appliedParagraphStyle = app.activeDocument.paragraphStyles.itemByID(locateParagraphStyle("Table body, cond, center"));

      var myFound = mySelection.changeGrep();

      alert ("Search is completed. " + myFound.length + " replacement(s) made.")


      // merge the cell with the two cells to the right

      for (i=myFound.length-1; i>=0; i--) { // iterate through each found occurance

      var myCell = myFound[i].parent;

      var myTable = myCell.parent;

      var myRow = myCell.parentRow.index;

      var myColumn = myCell.parentColumn.index;