4 Replies Latest reply on May 14, 2010 8:12 AM by Econometric

    table ID number.


      Hello -


      I recently took on a script from a co-worker no longer with the company that takes Excel data and places it into inDesign tables.  The script uses an InDesign template that is the same for all reports and updates it with the data from Excel.  The issue I am having, is that I want to add tables to the template and instruct the script to enter new data into them.  But I have no idea how to get the ID, which below is "17176".  The script currently uses several of these expressions and the IDs do not change, the script has been working very well for thousands of reports.  But once I add a new table to the template, how do I get the tableID?  I have been trying very hard for a while now and it is begining to feel hopeless.  Can anyone out there tell me how to obtain the tableID?


        If ReportType = 1 Then idDoc.TextFrames.Item(1).Tables.ItemByID(17176).Cells(2).Contents = ...etc


      Thank you,



        • 1. Re: table ID number.
          [Jongware] Most Valuable Participant

          The table ID is an internal number, assigned by InDesign itself, and should be different for all tables. It's simply the number "someTable.ID" (I guess -- check the VBS Script help).


          It's somewhat weird to use a specific table id value in a script ... it will only work for that one single table, as present in the actual template. If you delete this table and add a new one, it will, most probably, have another id assigned to it. And, of course, any other table will have (by definition) another id.

          1 person found this helpful
          • 2. Re: table ID number.
            Econometric Level 1

            Thank you for your post Jongware.  I understand it might not be technically correct to script this way, but I am a new scripter and only want to sustain the original process currently.


            What I know is that when I have manipulated the template (moved tables, deleted tables, etc) the table ID's have not changed.  I often add new tables and the script runs perfectly, but of course does not populate the new tables since I haven't scripted anything - since I don't know the ID.  What would someone like me do to learn how to get the table ID from tables on my template?



            • 3. Re: table ID number.
              [Jongware] Most Valuable Participant

              You would need to learn how to script


              (Sorry -- couldn't resist.)


              I don't know how to code it into VBS, as I'm more a Javascript person, but since you only need to get the right ID for your tables, this Javascript should work just fine for you. Run it with your cursor somewhere (anywhere!) inside a table, and the pop-up alert shows you the ID. Then you can change that in your VBS.


              This script looks like it's doing a lot of work, and you are correct. This one simple line ought to work


              alert (app.selection[0].id);


              but only if you always select the entire table! If you accidentally select just a single cell, you'll get the ID of that cell. For other selections (or none at all) you might just get an error message.

              Since it's hard to remember (well, for me it is) "on" what sort of object any script should run, I usually build in a lot of checks, and when possible, try to get to the target from your current selection. That takes some care, as users are prone to trying to run some of my scripts in unexpected circumstances ... (e.g., without even having a document on screen). It also needs quite some background knowledge of how ID's object hierarchy works -- in this case, the parent-child relations of a table and everything inside it.

              Enough about that. Let's get ta work.


              The selection "length" should be '1', because the script cannot work with any multiple selections (i.e., like a number of rectangles). If you have nothing selected, the selection length is 0 and the script cannot work either ...

              Then it checks if the selection has a property called "baseline". This would indicate you have a plain text cursor, somewhere inside (hopefully) a table cell. If so, the variable myTable is shifted up a notch to the plain text 'parent' -- which can be just about anything!


              So a few more checks are needed. If the variable shifted "up" one level from text and you are inside a table, it will point to a Cell. Likewise, if you selected a single cell in its entirety, it will point to a Cell. If so, the next level 'up' is the table itself.


              However, it's also possible to select an entire row or column -- and the selection will point to that instead! In both cases, the immediate parent is the table itself.


              If you selected the entire table, all previous checks will fail and the selection type will be "Table" right away -- all previous checks will fail, but that doesn't really matter here.


              Finally, if after all those checks "myTable" does point to a table, it shows the ID value in an alert box.



              (Since this is a Javascript, copy and paste into a plain text editor -- Notepad, TextEdit in plain text mode, or Adobe's ESTK, for example -- and save as "ShowTableId.jsx" into your User Scripts folder.)



              //DESCRIPTION:Show Table ID for a selected table
              // Jongware, 14-May-2010
              if (app.selection.length == 1)
                   myTable = app.selection[0];
                   if (myTable.hasOwnProperty ("baseline"))
                        myTable = myTable.parent;
                   if (myTable instanceof Cell)
                        myTable = myTable.parent;
                   if (myTable instanceof Row)
                        myTable = myTable.parent;
                   if (myTable instanceof Column)
                        myTable = myTable.parent;
                   if (myTable instanceof Table)
                        alert ("Table ID is "+myTable.id);
              • 4. Re: table ID number.
                Econometric Level 1

                Jongware - thank you so much for you help.  This worked perfectly.  I appreciate you taking the time to be so clear and helpful.


                Thanks again!