Article View: adobe.scripting.indesign
Article #15764InDesign CS Indexing (JavaScript, but applicable to all languages)
From: Olav_Kvern
Date: Thu, 13 Nov 2003 22:28
Date: Thu, 13 Nov 2003 22:28
32 lines
2297 bytes
2297 bytes
Gang--
Scripting the creation of index topics with subtopics can be a real brain-twister. When you look at the InDesign CS object model, you'll see that the index object has a topics collection, and that you can tell the index to add a topic:
//given an index "myIndex"
var myTopic = myIndex.topics.add("Mammals");
So far, so good. Next, we can see that topics include a subtopics collection, and that we can add a subtopic as follows:
var mySubtopic = myTopic.subtopics.add("Bats");
The subtopic "Bats" shows up on the "Mammals" topic, just as one would expect. Let's say we want to add a further subtopic--now things get confusing (at least for me). Here's what doesn't work:
var myTopic = myIndex.topics.add("Mammals");
var mySubtopic = myTopic.subtopics.add("Bats");
var mySubSubTopic = myTopic.subtopics.add("Vampire");
The above script produces the index topics "Mammals, Bats," and "Mammals, Vampire," when what we wanted was "Mammals, Bats, Vampire." It took me (and Stan Somers, another Adobe guy) a while to figure out the right approach (Stan's the one who really got it to work). Here it is:
var myTopic = myIndex.topics.add("Mammals");
var mySubtopic = myTopic.subtopics.add("Bats");
var mySubSubTopic = mySubtopic.parent.subtopics.add("Vampire");
What the...? Aren't myTopic and mySubtopic.parent the same object? As it turns out, they're not. When you tell myTopic to create mySubtopic, what you're really doing is creating *another topic*. It's that topic, not myTopic, that you want to have create the subtopic.
Hope this helps any poor soul who's been trying to create index topics via scripting!
Thanks,
Ole
Technical Details
Message-ID:
<2cce6115.-1@webx.la2eafNXanI>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!webxShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f939a,289ff5ae7c36f46a,start X-Google-Attributes: gidf939a,public X-Google-ArrivalTime: 2003-11-13 14:38:03 PST From: Olav_Kvern@adobeforums.com Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!webx Newsgroups: adobe.scripting.indesign Subject: InDesign CS Indexing (JavaScript, but applicable to all languages) Message-ID: <2cce6115.-1@webx.la2eafNXanI> Date: Thu, 13 Nov 2003 14:28:11 -0800 Lines: 36 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit