5 Replies Latest reply on May 31, 2010 8:26 AM by Peter Kahrel

    Select a table

    Xakie Level 1

      Can anybody tell to me how to select a table through scripting. InDesign CS3, Javascript

       

      Thanks.

      Xakie

        • 1. Re: Select a table
          Anil Yadav Level 1

          Hi Xakie,

           

          Here is the code:

           

          app.select(app.activeDocument.textFrames[0].tables[0]);
          


          Regards,

          Anil Yadav

          • 2. Re: Select a table
            Xakie Level 1

            Thanks Yadav,

             

            but didn't worked, getting this error:

            error.jpg

            Am new to scripting, what's wrong here?

             

            Xackie

            • 3. Re: Select a table
              Peter Kahrel Adobe Community Professional & MVP

              Xakie,

               

              If the first text frame in your document doesn't contain a table, then Anil's code doesn't work. It depends on where your table is and what state your document is in. Here are some approaches:

               

              1. If you have an insertion point selected in a table, do this:

              app.selection[0].parent.parent.select();

               

              2. If you have a text frame selected which has a table in it, then do this:

              app.selection[0].tables[0].select();

               

              3. To find all tables in the document and select the first one (though "first" is a variable and fluid concept here):

              app.documents[0].stories.everyItem().tables.everyItem().getElements()[0].select();

               

              But do you really want to select a table? Whenever possible avoid working with selected items. To do something with a table, you could also address it as an object:

               

              myTable = app.selection[0].tables[0];

              myTable.cells[0].contents = "First cell";

              ...

              ...

               

              Peter

              • 4. Re: Select a table
                Xakie Level 1

                Great! Simply superb.

                Me trying to select all tables from a document. Then applying the table styles.

                 

                Once again thanks for the tips.

                Xakie

                • 5. Re: Select a table
                  Peter Kahrel Adobe Community Professional & MVP

                  You can use this one-liner for that:

                   

                  app.activeDocument.stories.everyItem().tables.everyItem().appliedTableStyle = myTableStyle;

                   

                  Peter