🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #1736

Re: [CS4 JS] Scripting Indexes

#1736
From: Peter Kahrel
Date: Wed, 28 Jan 2009 15:25
50 lines
1970 bytes
Rick,

Here's (a variant of) a script that I sometimes use to deal with indexes. Its output is an array of strings of topics followed by their page numbers. Topics and numbers are separated by // so you can find them easily. Subtopics are separated by #. So you get something like this:

Basque//1, 2, 3, 4
Romance#Italian//1, 2, 3, 4

Peter



#target indesign;

rough_index = manual_index (app.activeDocument);

function manual_index (doc) 
   { 
   var indexx = []; 
   t = app.activeDocument.indexes[0].allTopics; 
   for (i = 0; i < t.length; i++) 
      { 
      prefs = t[i].pageReferences.everyItem().getElements(); 
      if (prefs.length > 0) 
         { 
         topic = topic_path (t[i], t[i].name); 
         pages = find_pages (prefs); 
         indexx.push (topic + '//' + pages) 
         } 
      } 
   return indexx 
   }

function topic_path (top, str) 
   { 
   if (top.parent.constructor.name == 'Index') 
      return str; 
   else 
      return topic_path (top.parent, top.parent.name + '#' + str) 
   }

function find_pages (page_refs) 
   { 
   var temp = []; 
   for (var i = 0; i < page_refs.length; i++) 
      { 
      try {temp.push (page_refs[i].sourceText.parentTextFrames[0].parent.name)} 
      catch (_){} 
      } 
   return temp.join (', ') 
   } 
Technical Details
Message-ID: <59b7ae01.18@webcrossing.la2eafNXanI>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news.glorb.com!news2.glorb.com!news.glorb.com!newshub.sdsu.edu!webcrossing
References: <59b7ae01.-1@webcrossing.la2eafNXanI>

Show Full Headers
Complete Article Headers
X-Google-Thread: f939a,6b07b633d95c342d
X-Google-Attributes: gidf939a,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Peter Kahrel" <kahrel@kahrel.plus.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news.glorb.com!news2.glorb.com!news.glorb.com!newshub.sdsu.edu!webcrossing
Newsgroups: adobe.scripting.indesign
Subject: Re: [CS4 JS] Scripting Indexes
Message-ID: <59b7ae01.18@webcrossing.la2eafNXanI>
Date: Wed, 28 Jan 2009 07:25:12 -0800
References: <59b7ae01.-1@webcrossing.la2eafNXanI>
Lines: 58
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit