1 Reply Latest reply on Jun 6, 2013 11:49 AM by Jump_Over

    Snap all rows in table/document

    Jennifer Hearing Level 1

      I've been working through the book  "Scripting InDesign with JavaScript." The script is originally for snapping columns, but I'm trying to snap all the rows in tables so I've changed the references to "rows." I've worked through to this point, but it still snaps only the row where the cursor is located. I'm not sure what I need to alter in order for it to snap every row.


      //from Scripting InDesign with JavaScript
      var myStories = app.activeDocument.stories
      for( var i = 0; i < myStories.length; i++ )
          for( var j = 0; j < myStories[i].tables.length; j++ )
          for( var k = 0; k < myStories[i].tables[j].rows.length; k++ )
              snapRow( myStories[i].tables[j].rows[k] )
      function snapRow( myRow )
      // get the size of em space
      var em = myRow.cells[0].insertionPoints[0].pointSize;
      myRow.height = '2p3';
      // get horizontal offset of last insertion point in each cell
      var myRightPosArray = myRow.cells.everyItem(
      // find the biggest value
      var longest = maxArray( myRightPosArray )
      // get position of left side of Row
      var myLeftPos = myRow.cells[0].insertionPoints[0].horizontalOffset
      // set Row height
      myRow.height = (( longest - myLeftPos ) + em )
      function getRow()
      var mySel = app.selection[0];
      if( mySel.parent.constructor.name == 'Cell' )
      return mySel.parent.parentRow
      else if( mySel.constructor.name == 'Cell' )
      return mySel.parentRow;
      alert( 'Cursor not in a table\ror illegal selection' );
      function maxArray( myArray )
      var temp = 0
      for( var i in myArray )
      temp = Math.max( temp, myArray[i] )
      return temp
        • 1. Re: Snap all rows in table/document
          Jump_Over Level 5



          Exam a function snapRow() ==> snapColumn() in original, probably.

          It is a horizontalOffset property used to find a widest cell in column.

          This is useless if the goal is to snap row's height.


          There is  .autoGrow property useful for rows.

          You could combine this with maximumHeight & minimumHeight (or not)


          So simplest way :

          snapRow(myRow) {
               myRow.autoGrow = true;


          getRow() function is useless too