4 Replies Latest reply on Aug 30, 2010 5:17 AM by studioavanti

    Find styled cell / Change row height

    studioavanti Level 1

      Hello,

       

      I try to do with a script what InDesign (even CS5) cells styles doesn't : globally change row height on several styled cells at once.

      But i'm just a graphic designer and new to ID scripting, so it's not easy…

       

      I think first step could be : find all "myCellStyle" styled cells on the whole document.

      I tried something like this but did'nt work (shows "Not found" alert) :

       

      function findTable(obj) {
           while (obj.constructor.name != "Table") {
                obj = obj.parent;
                if (obj.constructor.name == "Application") {
                     throw "Can't find table"
                }
           }
           return obj
      }
      
      var myTable = 0;
      if (app.documents.length > 0 && app.selection.length > 0) {
           myTable = findTable(app.selection[0]);
      }
      
      // Find styled celles formater
      if (myTable != 0) {
           if (myTable.cells.everyItem().appliedCellStyle == "myCellStyle") {
                alert("Found"); 
           } else {
                alert("Not found");
           }
      }
      

       

      Second step could be : change rows height when containing found cells.

       

      Thanks for your help that may interest other people too (?)

        • 1. Re: Find styled cell / Change row height
          Shonkyin Level 3

          You can't search paragraph style with below code

               if (myTable.cells.everyItem().appliedCellStyle == "myCellStyle") {

           

          Here is working code on CS4

           

          function findTable(obj) {
               while (obj.constructor.name != "Table") {
                    obj = obj.parent;
                    if (obj.constructor.name == "Application") {
                         throw "Can't find table"
                    }
               }
               return obj
          }
           
          var myTable = 0;
          if (app.documents.length > 0 && app.selection.length > 0) {
               myTable = findTable(app.selection[0]);
           
          //Find styles cells formater
          if (myTable.constructor.name ==  "Table")
          {
               app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
               app.findTextPreferences.appliedParagraphStyle = "myCellStyle";
               var myCellStyle = myTable.findText();
               app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing; 
          }
          if (myCellStyle.length>0)
          {
          for (var c = 0; c<myCellStyle.length; c++)
          {
               myCellStyle[c].parent.parentRow.height = "2p"; //Change row height as per your requirement
          }
          }
          else{alert("Not found");}
          }
          

           

           

          Shonky

          • 2. Re: Find styled cell / Change row height
            studioavanti Level 1

            Hi Shonkyin,

            Thanks for your answer but i don't understand why your script search for a paragraph style.

            I try to change styled cells (with a cell style, not a paragraph style) height in tables.

            I work with INDD CS5 and the script send me an error 30477.

            • 3. Re: Find styled cell / Change row height
              Shonkyin Level 3

              Yes dear it is created for search paragraph style in table and change row height.

               

              Try below one with Cell style

               

              function findTable(obj) {
                   while (obj.constructor.name != "Table") {
                        obj = obj.parent;
                        if (obj.constructor.name == "Application") {
                             throw "Can't find table"
                        }
                   }
                   return obj
              }
               
              var myTable = 0;
              if (app.documents.length > 0 && app.selection.length > 0) {
                   myTable = findTable(app.selection[0]);
              }
               
              // Find styled celles formater
              if (myTable != 0) {
                   var myCellStylesLen = myTable.cells.length;
                   var myFound = 0;
                   for (var a=0; a<myCellStylesLen; a++)
                   {
                        if(myTable.cells[a].appliedCellStyle.name == "myCellStyle")
                        {
                             myTable.cells[a].parentRow.height = "2p"
                             myFound++
                        }
                   }
                   
                   if (myFound == 0)
                    {
                         alert("Not found");
                   }
              }
              
              

               

               

              Shonky

              • 4. Re: Find styled cell / Change row height
                studioavanti Level 1

                Works OK, thanks a lot.