CS4 JavaScript for creating an index based on paragraph style

Copy link to clipboard
Copied
I need to create an index based on a paragraph style. Essentially, where ever the paragraph style "Name" occurs in my document I would like to place an index marker which encapsulates all the contents of "Name." I have tried this with GREP, but cannot (as far as I know) insert an index marker using this method.
I would like to create a javascript which will loop through my document and tag each instance of "Name" with an index maker, but I am too much of a js noobie to figure this out. Has anyone found a solution to a similar problem?
Any help is much appreciated.
Thx
cditcher
Copy link to clipboard
Copied
Here are the bare bones, not much error checking. An existing index is left in place, new items are added to it.
Peter
#target indesign; myDoc = app.documents[0]; if (myDoc.indexes.length == 0) myDoc.indexes.add (); app.findGrepPreferences = null; app.findGrepPreferences.findWhat = "^.*"; app.findGrepPreferences.appliedParagraphStyle = myDoc.paragraphStyles.item ('Name'); myFound = myDoc.findGrep (true); for (i = 0; i < myFound.length; i++) { try { newTopic = myDoc.indexes[0].topics.add (myFound.contents); newTopic.pageReferences.add (myFound, PageReferenceType.currentPage); } catch (_){} }

Copy link to clipboard
Copied
Thanks Peter! You've saved us all alot of work. The script works very well.
Cheers,
Chris

