2 Replies Latest reply on Aug 16, 2013 8:33 AM by Jennifer Hearing

    Change row color by found grep text

    Jennifer Hearing

      I'm using InDesign CS 5 on a Mac. I've altered the following script to find the word "Base" and apply a fill color to the cell.


      But I'm also trying to figure out the following:

      1. search only within selected table (I tried changing it to var docTables = app.selection[0];, but got an error for o = docTables.length that I'm not sure how to fix.)

      2. add Grep search looking for "Base" with "chart semibold" character style attached (I tried playing with this code I use elsewhere, but can't figure how to merge the two . . .

      app.changeGrepPreferences.appliedCharacterStyle = app.activeDocument.characterStyles.item("chart semibold");)

      3. apply the fillColor to the entire row. I tried playing around with the parentRow command, but not very successful there either.


      app.findGrepPreferences = NothingEnum.nothing;   
        //[Grep, cellStyleName]
      var grepSearch = [["Base"]]  
      var docTables = app.activeDocument.stories.everyItem().tables.everyItem().getElements();  
      o = docTables.length;  
      for(var i = 0; i < o;i++){  
          myTable = docTables[i];  
      l = grepSearch.length;  
      app.findGrepPreferences.findWhat = grepSearch[l][0];   
      var foundList = myTable.findGrep();   
      f = foundList.length;  
      while(f--){foundList[f].parent.fillColor = "PANTONE 3005 C 45%";}
      app.findGrepPreferences = NothingEnum.nothing;


      Thanks for any help with any of these issues.

        • 1. Re: Change row color by found grep text
          Jump_Over Level 5

          Hi Jennifer,


          I suggest to make some clearings:


          1. to catch a table starting from selection select something inside a desired table and check parent instance till success.

          2. you are merging Grep conditions while assigning a value to consecutive preferences

          (so your try should work in fact). To refer to the row from a cell content (found text) use text.parent.parentRow

          3. assign a swatch to a .fillColor property


          So try this:

          var mSel = app.selection[0],
          mCheck = mSel instanceof Table || mSel instanceof Document;
          while (!mCheck) {
                    mSel = mSel.parent;
                    mCheck = mSel instanceof Table || mSel instanceof Document;
          if (mSel instanceof Document) {alert ("Select anything inside a table"); exit();}
          app.findGrepPreferences = NothingEnum.nothing;   
          var grepSearch = ["Base"] ,
          l = grepSearch.length, 
          mStyle = app.activeDocument.characterStyles.item("chart semibold"),
          mSwatch = app.activeDocument.swatches.item("PANTONE 3005 C 45%");
          app.findGrepPreferences.appliedCharacterStyle = mStyle;
          while(l--) {  
                    app.findGrepPreferences.findWhat = grepSearch[l];   
                    foundList = mSel.findGrep();   
                    f = foundList.length;  
                    while(f--) {
                    foundList[f].parent.parentRow.fillColor = mSwatch;
          app.findGrepPreferences = NothingEnum.nothing;



          • 2. Re: Change row color by found grep text
            Jennifer Hearing Level 1

            Thanks -- that worked!