4 Replies Latest reply on Oct 19, 2009 5:56 AM by jenlynn11

    Script all of a sudden not working


      I've had success using a script to fill in empty cells in a talbe with a space and applying a paragraph and character style...until today. I haven't used it in a month or two so I was wondering if an update is causing it to not be "valid" anymore? Here's the script:


      for (a=0; a<app.selection[0].parent.parent.cells.length; a++)
      if (app.selection[0].parent.parent.cells[a].contents.length == 0)
        app.selection[0].parent.parent.cells[a].contents = " ";
        app.selection[0].parent.parent.cells[a].paragraphs[0].appliedParagraphStyle = app.activeDocument.paragraphStyles.item("Empty Cell");
      app.selection[0].parent.parent.cells[a].paragraphs[0].appliedCharacterStyle = app.activeDocument.characterStyles.item("[None]");




      And here's the error message I'm getting in CS4 while trying to use it:


      Error String: Object does not support the property or method 'cells'

      Line: 1

      Source: for (a=0; a<app.selection[0].parent.parent.cells.length; a++)



      Any help would be greatly appreciated!!!

        • 1. Re: Script all of a sudden not working
          Jeremy bowmangraphics-DQuh1B Level 3

          When you run the script, do you have some text selected, or the flashing cursor somewhere inside a cell? I don't think it would work if the entire table or some cells were selected.

          • 2. Re: Script all of a sudden not working
            jenlynn11 Level 1

            I had the entire table selected...details, details....


            Thank you. Yes it worked with the cursor inside a cell. (Boy do I feel embarassed!)

            • 3. Re: Script all of a sudden not working
              [Jongware] Most Valuable Participant

              Isn't that one of my masterpieces? I seem to recognize its (lack of) style ...

              Jen, if the script does a little basic checking before running, you don't have to worry anymore where and how the cursor should be placed. This little change should do that:


              pos = app.selection[0];
              if (pos.hasOwnProperty("baseline"))
               pos = pos.parent;
              while (pos.constructor.name == "Cell")
               pos = pos.parent;
              if (pos.constructor.name == "Row")
               pos = pos.parent;
              if (pos.constructor.name != "Table")
               alert ("Eh? Not in a table?");
              for (allCells=0; allCells<pos.cells.length; allCells++)
               if (pos.cells[allCells].contents.length == 0)
                pos.cells[allCells].contents = " ";
                pos.cells[allCells].paragraphs[0].appliedParagraphStyle = app.activeDocument.paragraphStyles.item("Empty Cell");
                pos.cells[allCells].paragraphs[0].appliedCharacterStyle = app.activeDocument.characterStyles[0];// .item("[None]");


              I changed the 'characterStyle' line to use style #0 instead of the name "[None]", as it appears to disagree with my old CS. This script now ought to work on anything from CS to CS4.

              • 4. Re: Script all of a sudden not working
                jenlynn11 Level 1

                Wow! Thank you very much! Now I won't have to rely on my memory as much. Greatly appreciated!!