3 Replies Latest reply on Oct 28, 2016 1:15 AM by Obi-wan Kenobi

    Code to be evaluated! [003]

    Obi-wan Kenobi Adobe Community Professional

      Hi Scripters!

       

      is it possible to concentrate more … and of course make it work!? 

       

      var myTables = app.activeDocument.stories.everyItem().tables.everyItem().getElements();    
            
      for ( var t = 0; t < myTables.length; t++ ) {  
              if ( myTables[t].appliedTableStyle.name == "xxx" && myWidths = [30, 10, 25, 30] )  
                  for (var c = 0; c < myWidths.length; c++) myTables[t].columns[c].width = myWidths[c];  
              if ( myTables[t].appliedTableStyle.name == "yyy" && myWidths = [10, 20] )  
                  for (var c = 0; c < myWidths.length; c++) myTables[t].columns[c].width = myWidths[c];  
              if ( myTables[t].appliedTableStyle.name == "zzz" && myWidths = [10, 50, 30] )  
                  for (var c = 0; c < myWidths.length; c++) myTables[t].columns[c].width = myWidths[c];  
      }  
      
      
      

       

      (^/)

        • 1. Re: Code to be evaluated! [003]
          Peter Kahrel Adobe Community Professional & MVP

          This is more concentrated:

           

          for ( var t = 0; t < myTables.length; t++ ) {
            switch (myTables[t].appliedTableStyle.name) {
              case 'xxx': myWidths = [30, 10, 25, 30]; break;
              case 'yyy': myWidths = [10, 20]; break;
              case 'zzz': myWidths = [10, 50, 30];
            }
            for (var c = 0; c < myWidths.length; c++) myTables[t].columns[c].width = myWidths[c];
          }
          

           

          But whether it works I've no idea.

           

          Peter

          1 person found this helpful
          • 2. Re: Code to be evaluated! [003]
            Obi-wan Kenobi Adobe Community Professional

            Hi Peter,

             

            With, as beginning:

             

            var myTables = app.activeDocument.stories.everyItem().tables.everyItem().getElements();      
            

             

            Nice code!  It works fine!

             

            I'm going to study it! 

             

            Thanks!

             

            (^/)

            • 3. Re: Code to be evaluated! [003]
              Obi-wan Kenobi Adobe Community Professional

              Even if  the user needs to enter his own table styles and columns numbers/widths per style in the script, its code is really easy to read and understand!

              Just follow the rabbit! 

               

               

              var myTables = app.activeDocument.stories.everyItem().tables.everyItem().getElements();      
              for ( var t = 0; t < myTables.length; t++ ) {  
                switch (myTables[t].appliedTableStyle.name) {  
                  /* 
                      Just replace 'xxx', 'yyy', 'zzz', … by your own table styles.
                      Insert the column widths per table style you want to be applied: here, [30, 10, 25, 30], about a 4-columns table!
                      Eventually, add or delete lines.
                  */  
                  case 'xxx': myWidths = [30, 10, 25, 30]; break;  
                  case 'yyy': myWidths = [10, 20]; break;  
                  case 'zzz': myWidths = [10, 50, 30];  
                  default: alert ("No Table Style found! …\r(^/)  :("); exit ()
                }  
                for (var c = 0; c < myWidths.length; c++) myTables[t].columns[c].width = myWidths[c];  
              } 
              alert ("Done!\r(^/)  ;-)")
              

               

               

              When work is done! …

               

              Capture d’écran 2016-10-28 à 09.59.28.png

               

              If no table styles found! …

               

              Capture d’écran 2016-10-28 à 09.58.54.png

               

              (^/)