5 Replies Latest reply on Jul 18, 2009 7:11 AM by Brett Elliott

    [CS4-JS] Cell Contents Scaling Issue - Data out of Range

    Brett Elliott

       

       

      Hi guys it's been a long time and I am embraced to post as I have come a long way in the past year, but...

       

      I am trying to resize the contents of a range of cells in several tables, these contents may or may not be overset to the right side, but I have to change the whole style so they all look the same (company policy). I can do this if there is only one line and one style but my cells have 4 lines and 3 styles and 3 XML tags in each (and no I cannot split the cells as I have formatting parameters to follow, cells would be too big if I did split).

       

      So, I can select the contents of each line, word etc but when I try to scale them based on their paragraphStyle I get a 'data out of range error', or nothing happens, or all styles become 100%. What frustrates me more is I did get this to work but because I have been stuck on this for sooo long and my eyes are falling out of my skull I forgot what I did. Below is the code, could someone please point me in the right direction, I am losing what hair I have left on this supposedly simple task. Also, if I am going about this in the wrong way could you also let me know.

       


      var myCanPS = myDoc.paragraphStyles.item("CAN");

      var myGlyph = myCanPS.minimumGlyphScaling;

      var myMax;

       

      function resizeThirdOverset() {
                  myMax = 0;

                  // Select Tables
                  for (t = 34; t <= 65; t++) {

                      // Select Rows
                      for (r = 1; r <= myTables[t].rows.length-1; r++) {

                      // Without these two try's I get an error.
                      try {
                      // Catch the length of the first word and the length of the whole first line

                      wChar = myTables[t].rows[r].cells[1].words.item(0).characters.length;
                      } catch (myError){
                          }
                      try {
                      LChar = myTables[t].rows[r].cells[1].lines.item(0).characters.length - 2;
                      } catch (myError){
                          }

                      w = myTables[t].rows[r].cells[1].lines.item(0).words.length;

                      // See if the first word matches the length of the whole line

                      if (LChar = wChar) {
                      // w represents the number of words on the first line, if it is 1 then we can continue, more than one word has not beed delt with yet, first things first. The range of characters that can fit in the cell is 15, so is LChar <= 15 everything can be 100%.   

                      if (w == 1 && LChar <= 15) {
                                  myCanPS.desiredGlyphScaling = 100;
                                  myCanPS.minimumGlyphScaling = 100;
                                  myCanPS.desiredWordSpacing = 100;
                                  myCanPS.minimumWordSpacing = 100;
                                  myMax == 15;
                          }

                         // As LChar increases the scaling decreases in increments.

                         else if (w == 1 && LChar == 16 && myMax < 16) {
                              if (myGlyph > 95 && myGlyph <= 100) {
                                  myCanPS.desiredGlyphScaling = 95;
                                  myCanPS.minimumGlyphScaling = 95;
                                  myCanPS.desiredWordSpacing = 100;
                                  myCanPS.minimumWordSpacing = 100;
                                  myMax == 16;
                              }
                          }

                      else if(... and so on for as many cells as required, I do this three more times on the other contents.


      Any help would be greatly appreciated.

      Thanks, Brett

        • 1. Re: [CS4-JS] Cell Contents Scaling Issue - Data out of Range
          Peter Kahrel Adobe Community Professional & MVP

          Brett,

           

          I think you can simplify things by looking at all cells and while any cell is overset, reduce the spacing in any relevant paragraphs. Something like this:

           

          myBooleanArray = myTable.cells.everyItem().overflows;

          // myBooleanArray is an array of true/false

          while (check_overflow (myBooleanArray) == true)

             {

             // reduce the spacing in your paragraph styles

             }

           

           

          function check_overflow (myArray)   // array of booleans
            {

            // check if myArray contains any "true"

            // if it does, return true, otherwise return false
            for (i = 0; i < myArray.length; i++)
              if (myArray[i] == true)
                 return true;
            return false
            }

           

           

          You said you wanted to check just certain rows, but it's easier to look at the whole table (though maybe slower). But anyway, this approach can be adapted to target just certain rows.

           

          Peter

          1 person found this helpful
          • 2. Re: [CS4-JS] Cell Contents Scaling Issue - Data out of Range
            Brett Elliott Level 1

            Thank you very much Peter, I had a lot of trouble with using the 'overflows' command with cells. I will begin adding your script and let you know how I go, thanks again.

             

            Brett

            • 3. Re: [CS4-JS] Cell Contents Scaling Issue - Data out of Range
              Brett Elliott Level 1

              Hi Peter,

               

              I needed to change 1 line in your code "myBooleanArray = myTable.cells.everyItem().overflows;" it gave a "undefined is not a object" error.

               

              So, I iterated throught the table and respective cell.

               

              However, the code goes through the cells and returns the overflows value of true or false no worries but it doesn't initiate the line "while (check_overflow (myBooleanArray) == true) {".

               

              Do you know why this is the case? Below is the script.

               

              var myDoc = app.activeDocument;
              var myStories = myDoc.stories;
              var myTable = app.documents[0].stories.everyItem().tables.everyItem().getElements();

              var myATLPS = myDoc.paragraphStyles.item("ATLPTY2");

              resizeSecondOverset();
              // Resize overset.

              function resizeSecondOverset() {
                  myATLPS.desiredGlyphScaling = 100;
                  myATLPS.minimumGlyphScaling = 100;
                  myATLPS.desiredWordSpacing = 100;
                  myATLPS.minimumWordSpacing = 100;
                  for (t = 2; t <= 33; t++) {
                      for (c = 1; c <= myTable[t].cells.length-1; c++) {
                          myBooleanArray = myTable[t].cells[3].overflows;
                          // myBooleanArray is an array of true/false
                          while (check_overflow (myBooleanArray) == true) {
                              // reduce the spacing in your paragraph styles
                              myATLPS.desiredGlyphScaling = myATLPS.desiredGlyphScaling -1;
                              myATLPS.minimumGlyphScaling = myATLPS.minimumGlyphScaling -1;
                              myATLPS.desiredWordSpacing = myATLPS.desiredWordSpacing -0.75;
                              myATLPS.minimumWordSpacing = myATLPS.desiredWordSpacing -0.75;
                              }
                          function check_overflow (myArray) {
                              // array of booleans
                              // check if myArray contains any "true"
                              // if it does, return true, otherwise return false
                              for (i = 0; i < myArray.length; i++)
                              if (myArray[i] == true)
                              return true;
                              return false
                              }
                          }
                      }
                  }

              • 4. Re: [CS4-JS] Cell Contents Scaling Issue - Data out of Range
                Peter Kahrel Adobe Community Professional & MVP

                Brett,

                 

                In your code you look at just one cell (cells[3]) in each table, but you need to check all cells. In this line:

                 

                myBooleanArray = myTable[t].cells[3].overflows;

                 

                myBooleanArray is not an array but a single cell. You should cycle not through the array of cells, but through the array of booleans. I guess what you want is something like this:

                 

                for (t = 2; t <= 33; t++){
                   myBooleanArray = myTable[t].cells.everyItem.overflows;
                   while (check_overflow (myBooleanArray) == true) {
                       myATLPS.desiredGlyphScaling = myATLPS.desiredGlyphScaling -1;
                       myATLPS.minimumGlyphScaling = myATLPS.minimumGlyphScaling -1;
                       myATLPS.desiredWordSpacing = myATLPS.desiredWordSpacing -0.75;
                       myATLPS.minimumWordSpacing = myATLPS.desiredWordSpacing -0.75;
                       }
                    }

                 

                Does that make sense?

                 

                Peter

                1 person found this helpful
                • 5. Re: [CS4-JS] Cell Contents Scaling Issue - Data out of Range
                  Brett Elliott Level 1

                  Ahhh, yes it does make sense. I also found out that I had my desired and minimum paragraphStyles the wrong way round, you can't have desired value below minimum value in other words.

                   

                  Thank you very much Peter you've been a life saver.

                   

                  Brett