4 Replies Latest reply on Apr 6, 2016 8:39 AM by AMC012

    [CS 5.5][JS] Split table script

    JohnDevlon Level 1



      Based on a select row method  I found on this forum, I've created a basic table split script. Everything works fine. The script will create a new table above the old table, and moves all the content above the cell in which the curcor is located, to the new table.

      Now, I would like to modify the script to create a new table BELOW the current table and move all content below the current position to the new table. The problem is the insertion point. How do I create a new table after the current one?


      Thanx for any feedback.


      if(app.documents.length > 0){


                  var myOldTable = app.selection[0].parent.parent;

                  var myOldTablePosition = myOldTable.storyOffset; // insertionPoint

                  var myTextFrame = app.selection[0].parent.parent.parent;


                  var myCell = app.selection[0].parent;


                  var currentRowIndex = myCell.rows[0].index;

                  var totalNumOfColumns = myCell.rows[0].columns.length;

                  var totalNumOfRows = myOldTable.rows.length;


                  myNewTable = myOldTablePosition.tables.add({columnCount:totalNumOfColumns , bodyRowCount:currentRowIndex});


                  selectRows(myOldTable, 1, currentRowIndex);



                  selectRows(myNewTable, 1,1);





          alert("A Indesign file must be open !");   



      function selectRows(aTable, startRowIndex, endRowIndex){

           app.selection = NothingEnum.NOTHING;

           var _row = aTable.rows;


           for(var i=startRowIndex; i<endRowIndex;i++){

                app.select(_row[i], SelectionOptions.ADD_TO);