Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

CS4 JavaScript for creating an index based on paragraph style

Guest
May 11, 2009 May 11, 2009

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

TOPICS
Scripting
634
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 11, 2009 May 11, 2009

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 (_){}
  }
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 12, 2009 May 12, 2009
LATEST

Thanks Peter! You've saved us all alot of work. The script works very well.

Cheers,

Chris

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines