Skip to main content
Known Participant
January 19, 2010
Question

.ItemByID() how to obtain ID

  • January 19, 2010
  • 1 reply
  • 5700 views

Hello,

I have an Indesign document with several text tables.  What I would like to do is have a VBA script enter text into these tables.  I am using the .ItemByID() method.  However, I do not know how to obtain the table ID "x" so that the script knows which table to reference.  When I create the table in Indesign, is there a way to obtain the tables unique ID?

idDoc.TextFrames.ItemByID(x)

Thank you for your help,

Mike

This topic has been closed for replies.

1 reply

Harbs.
Legend
January 19, 2010

Table.id

Harbs

Known Participant
January 19, 2010

Thank you Harbs for helping me out with this, but I'm still not getting it.  If I create a table in my Indesign document, do you mean go to the table menu drop down to get the ID?  I don't see anything there that gives me the ID.  Hate to ask you to elaborate on such a simple task but I'm having trouble with this one.


Thanks again,
Mike

Jongware
Community Expert
Community Expert
January 19, 2010

The ID is an internal unique identifier for the table (the ESTK Help describes it as "The unique ID of the Table." -- kind of summarizes it). It's guaranteed to be unique for all tables throughout your entire document -- InDesign needs it to be for every single object to be able to put your file together from its bits.

I can sort of imagine how it works: what if you rename a paragraph style? If the styles were applied "by name", ID would have to scan the entire document for that name and change it. What if you move a paragraph style around in its palette? If the styles were applied by using their index number (the index being their position in the palette), ID again would need to re-scan the document. Instead, all styles are applied by UniqueID. All InDesign has to do now is making sure it does not re-use an ID when you create a new style. The Unique ID will stay the same, whatever you do with the style. And if there is no style with some ID in the paragraph style list, it does not exist. Period.

.. Totally made this up, of course, but it does sound good doesn't it!?

The ID is "hidden" -- not available in the User Interface, and read-only for scripting purposes. If I would be prone to guessing, I'd say it's even read-only in plugins, except (maybe) at the very deepest core.

This is a Javascript that shows the ID for the table your cursor is in. However, interesting as that may sound, logically, you might not need it. If you can read the ID of a table, you already have to have a valid handle on it. And if you do, you don't have to use ItemById ...

I think it could be useful to store the table IDs somewhere, do something else, then do something with the stored IDs. But you can always store direct pointers to the tables themselves ... (And -- again, guessing -- perhaps the scripting interface store these internally by referring to their ID.)

Perhaps you could better use the zero-based index (or, in the case of VBS, 1-based) of the tables in your story. The first index always will point to the first table, and so on all the way to the end of the story.

if (app.selection.length != 1)

{

     alert ("Please select more or less than this. Preferably a TABLE!");

     exit(0);

}

table = app.selection[0];

if (table.hasOwnProperty("baseline"))

     table = table.parent;

if (table.constructor.name == "Cell")

     table = table.parent;

if (table.constructor.name == "Row")

     table = table.parent;

if (table.constructor.name != "Table")

{

     alert ("Ah. Not in a table, are we?");

     exit(0);

}

alert ("Table Index: "+table.index+"\nTable Unique ID: "+table.id);