Skip to main content
Inspiring
October 12, 2007
Question

Scripting FAQ as Wiki

  • October 12, 2007
  • 32 replies
  • 3666 views
Mark Niemann-Ross of Adobe has generously allowed us to use the scripting section of his developers' wiki as a scripting FAQ. So, I've seeded a few pages (in the JavaScript section, of course) but wikis are communal efforts, so everyone is invited. But please don't use the wiki pages to ask questions; that's what these forums are for.

The discussion pages on the wiki can be used to asked for clarification of a page, but even then, you'll probably get a faster response and a bigger audience by asking here.

The FAQ address is listed in the Useful Resources space of the forum main page, as well as here:

http://www.niemannross.com/developer/wiki/index.php?title=InDesign_Scripting

To contribute to the FAQ (as opposed to just reading its contents), you'll need an OpenID. Took me a while to work out how to do that. What I did was go to:

http://getopenid.com/

and create an account. If you want more background information, click the 'What is OpenID' link on the left panel of the wiki.

I look forward to seeing people at the wiki and hope the content proves to be useful to everybody.
This topic has been closed for replies.

32 replies

Inspiring
October 15, 2007
Sorry, Ole but your description is not completely accurate.

ItemByName only returns a single item when the members of the collection have a name even if there are multiple objects in the collection with the same name.

As I demonstrated this morning, it works for labeled Tables.

While it also appears to work for labeled graphics, I'm not sure that it is actually possible to create a collection of graphics of length greater than one, so it's a bit academic that it works.

And xmlElements have neither a name or a label, so what it's doing there is even more mysterious. I agree with your advice to assume that it doesn't work reliably.

That's why I think a Wiki is a good place to keep this kind of information.

Dave
Known Participant
October 15, 2007
Fellow Scripters,

Here's how it works:

* If the object has a name property, ItemByName("myName") will return the item(s) named "myName".

* If the object is a page item (page item, rectangle, oval, graphic line, group, button, polygon, text frame), then ItemByName("myLabel") will return the item(s) with the label "myLabel".

* In all other cases, you cannot trust ItemByName to get an item by the contents of its label. In some cases, it will appear to work (XML elements), but don't be fooled.

Thanks,

Ole (back from sabbatical)
Inspiring
October 15, 2007
As a PS: this doesn't extend to cells of a table because cells also have names so itemByName works on the names, not the labels, even though the labels are visible in the panel.

Dave
Inspiring
October 15, 2007
This (combined with an appropriate selection holding an image labeled "Test") works:

myImage = app.selection[0].images.item("Test");
myImage.itemLink.name

And this fits my suggested rule that if the label can be seen in the Script Label panel it works. Aha, but table labels can be seen there. Let's try it with tables ...

Aha! This worked:

myStory = app.selection[0].parentStory;
myTable = myStory.tables.item("Test");
myTable.bodyRowCount

Now let me try it with more than one table in the story...

Added a three-row, unlabeled table before my "Test" table and it still worked. So now let's see what happens if I have two tables in the story both labeled "Test" ...

Golly! It worked. The script returned:

3,4

Dave
Participating Frequently
October 15, 2007
I will be traveling on business beginning Saturday the 13th of October and will have limited access to my email. I will be back in the office on Monday the 22nd of October. For emergencies please contact sales@anodos.gr, or call mob: +30 6977 215264.

Thank you.
Inspiring
October 15, 2007
At some point in the night, I realized that library assets have names, so they're not part of the issue at hand. It could indeed be that itemByName is only available for nameless, labeled items whose label can be seen in the Script Label panel.

Dave
Inspiring
October 14, 2007
Thanks for the input. I think it's a bit broader than that. For example, Library Assets support itemByName. I don't have the energy to do a comprehensive evaluation. I guess I'll just add objects to the unsupported list as I discover them. Anyone else is welcome to do the same.

Dave
Inspiring
October 14, 2007
On 15/10/07 1:13 AM, "Dave Saunders" <member@adobeforums.com> wrote:<br /><br />> I'm sure there's more.<br /><br />If it mirrors the AppleScript situation, the only classes that support it<br />are page items and its various subclasses (at least, I'm pretty sure that's<br />what Ole said on the matter).<br /><br />-- <br />Shane Stanley <sstanley@myriad-com.com.au><br />AppleScript Pro Florida, Feb 2008 <a href=http://scriptingmatters.com/aspro>
Inspiring
October 14, 2007
Feel free to open an account and contribute to the FAQ.

I'll add stories. I was thinking as I walked back from lunch at my daughter's house that stories was another example.

Dave
Harbs.
Legend
October 14, 2007
Dave_Saunders@forum.adobe.com wrote:
> Feel free to open an account and contribute to the FAQ.
>
>
I'll try to do that. I've never participated in a wiki before, but
there's a first for everything! :)

Thanks for the great work!

Harbs
Participating Frequently
October 14, 2007
I will be traveling on business beginning Saturday the 13th of October and will have limited access to my email. I will be back in the office on Monday the 22nd of October. For emergencies please contact sales@anodos.gr, or call mob: +30 6977 215264.

Thank you.