3 Replies Latest reply on Dec 30, 2013 11:54 AM by Tiggermn8278

    Looking for a Script to Add Rows in Multiple Places in a Table

    Tiggermn8278

      Hello all!

       

      I'm new to InDesign Scripting and I have been hunting around trying to find anything that would possibly work, and I just can't quite find it. I hope someone can help!

       

      I have a book that has tons of tables in it. They are all the same table. 2 Columns by 10 rows. Here is my dilemma:

       

      My client wants to add new rows to these tables, specifically:

      • A new row at the beginning of the table
      • A row after the already established 3rd row
      • 3Rows after the already established 9th row

       

      Is this even possible with a script?

       

      (I mention "already established" row, because I'm not sure if once the script adds that first row at the top, if that then changes the numbers of the rest of the rows -- and so on when more are added.)

       

      Any help would be MUCH appreciated.

        • 1. Re: Looking for a Script to Add Rows in Multiple Places in a Table
          Daniel Sterchi Adobe Community Professional

          Hi Tiggermn8278

           

          This might help you a bit, I hope.

          This is for the first table.

           

          *********************************************************

          main();

          exit();

           

          function main() {

              var myDoc = app.activeDocument;

           

          // first you need something to get hold of the tables

          // this is for the first talble in the first story

              var myStory = myDoc.stories[0];

              var myTable = myStory.tables[0];

           

              var ninthRow = myTable.rows[9];

              myTable.rows.add(LocationOptions.BEFORE, ninthRow);

           

           

              var ninthRow = myTable.rows[9];

              myTable.rows.add(LocationOptions.BEFORE, ninthRow);

           

           

              var ninthRow = myTable.rows[9];

              myTable.rows.add(LocationOptions.BEFORE, ninthRow);

           

           

              var thirdRow = myTable.rows[3];

              myTable.rows.add(LocationOptions.BEFORE, thirdRow);

           

           

              myTable.rows.add(LocationOptions.AT_BEGINNING);

          }

          *********************************************************

           

          kind regards

           

          Dani (from Switzerland)

          1 person found this helpful
          • 2. Re: Looking for a Script to Add Rows in Multiple Places in a Table
            Kai Rübsamen Adobe Community Professional

            Hi,

             

            what is a book for you? One document or a real Indesign-book-file with several documents?

             

            One document:

            var curDoc = app.activeDocument;

             

            var allTables = curDoc.stories.everyItem().tables.everyItem().getElements();

             

            for ( var t = 0; t < allTables.length; t++ ) {

                var curTable = allTables[t];

                var allRows = curTable.rows;

                curTable.rows.add(LocationOptions.AFTER, allRows[8]);

                curTable.rows.add(LocationOptions.AFTER, allRows[8]);

                curTable.rows.add(LocationOptions.AFTER, allRows[8]);

                curTable.rows.add(LocationOptions.AFTER, allRows[2]);

                curTable.rows.add(LocationOptions.AT_BEGINNING);

            }

             

            Several closed documents in a book file:

            This assumes, that only one book file is open!

             

            app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;

             

            var curBook = app.books[0];

            var allDocuments = curBook.bookContents;

             

            for ( var n = 0; n< allDocuments.length; n++ ) {

                var curDoc = app.open( File( allDocuments[n].fullName ) );  

             

                var allTables = curDoc.stories.everyItem().tables.everyItem().getElements();

             

                for ( var t = 0; t < allTables.length; t++ ) {

                    var curTable = allTables[t];

                    var allRows = curTable.rows;

                    curTable.rows.add(LocationOptions.AFTER, allRows[8]);

                    curTable.rows.add(LocationOptions.AFTER, allRows[8]);

                    curTable.rows.add(LocationOptions.AFTER, allRows[8]);

                    curTable.rows.add(LocationOptions.AFTER, allRows[2]);

                    curTable.rows.add(LocationOptions.AT_BEGINNING);

                } 

                // optional

                // curDoc.save();

                // curDoc.close();

            }  

             

            app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;

            • 3. Re: Looking for a Script to Add Rows in Multiple Places in a Table
              Tiggermn8278 Level 1

              THANK YOU! It was for one document, so that script worked PERFECTLY! It was EXACTLY what I was looking for!

               

              This just saved me HOURS of manually adding rows to over 300+ tables!