9 Replies Latest reply on Feb 4, 2011 6:54 AM by kristianjuul

    dynamic resizing of too wide columns (javascript, CS5)


      Hey. I'm just getting started at scripting for InDesign (and am realizing how much time I've been wasting these last too many years). So far, I've managed to solve minor problems myself, but this one I just don't know enough to get round. I appreciate that what's needed for the solution is likely a quite large piece of code, so I'm grateful for any advice you can give, be it just hints or nudges in the right direction.


      What I have to start with is this little piece of code which just applies a cell style to all tables in the selected text frame:


      var myTextFrame = app.selection[0];

      var myTables = myTextFrame.parentStory.tables.everyItem();
      var myTableCells = myTextFrame.parentStory.tables.everyItem().cells.everyItem();

      myTableCells.appliedCellStyle = "NameOfCellStyle";


      What I need to do from here is to search for any of the tables in myTables that:


      1) are wider than myTextFrame (that is, wider than the text frame they're in)

      2) have exactly two columns

      3) have a first column wider than the second column


      In these tables, the first column needs to be resized so that the table fits exactly inside myTextFrame.

      The best solution would be a dynamic resizing that isn't dependent on specific numbers, because the size of myTextFrame may vary, but right now I'll settle for anything, even if it means creating several scripts for different text frame widths.


      So there. After way too many failed attempts, which largely spring from me having very little clue what I'm doing, I'm about to give up. Any help or hint is greatly appreciated.