5 Replies Latest reply on May 27, 2014 4:21 AM by jdegheest

    Resizing column width of multiple selected stories with tables

    jdegheest

      I've found this wonderful script that fits the width of all tables to the width of their text frames

      It's brilliant because we have multiple layers, each layer containing tables in their own language. So the script helps a lot.

      There's only one thing I'd like to change:

      In this case, the script runs through the entire document. I'd like to change that to only the frame we select (to maximize control and avoid mistakes).

       

      ----------------------------------------------------------------------

       

      var myDocument=app.activeDocument;

       

      for (s=0; s<myDocument.stories.length; s++) {

       

              for (t=0; t<myDocument.stories[s].tables.length; t++) {

        

                  var myTable = myDocument.stories.item(s).tables.item(t);

                  var myTableParent = myTable.parent;

                  var parentWidth = myTableParent.geometricBounds[3] - myTable.parent.geometricBounds[1];

                  var factor = parentWidth/myTable.width;

                  for (col=0; col<myTable.columns.length; col++) {

                      myTable.columns[col].width *= factor;

                      }

              }

      }