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

Straightforward script to add entry using paragraph style

Community Beginner ,
Oct 28, 2020 Oct 28, 2020

Copy link to clipboard

Copied

Hello all,

I am a novice to scripting in InDesign. Does anyone know of or can someone create a script that would select an entire paragraph of text given a particular style (Helvetica Bold)?

I have a 1000+ page directory with 33,000+ people listed, where the first paragraph (the person's name, in bold) needs to be added to an index:

Screen Shot 2020-10-28 at 11.04.21 AM.png

I have been doing this with the Find/Change dialog, searching for the "Provider" style, which selects the whole line (paragraph) so I can then click-add to the index. As you might imagine, this is mind-numbingly tedious.

Help, please! Any already-created scripts out there? I've found one that searches by character style, but then it also reverses a first/last name to last, first along with some other things... I don't know enough about scripts to edit it and I couldn't even get it to run.

TOPICS
Scripting

Views

407

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Oct 28, 2020 Oct 28, 2020

Give this a shot. Note it will add new Page References for already existing items in your index if you already have them. You'll want to start with a fresh index. 

 

 

if (!app.documents[0].indexes[0].isValid) {
   var index = app.documents[0].indexes.add();
} else {
   var index = app.documents[0].indexes[0];
}
app.findTextPreferences = NothingEnum.NOTHING;
//change 'indexName' below to the paragraphstyle to find, leaving the double quotes
app.findTextPreferences.appliedParagraphStyle = "indexN
...

Votes

Translate

Translate
Community Expert ,
Oct 28, 2020 Oct 28, 2020

Copy link to clipboard

Copied

Just use the Table of Contents feature to generate your index. It can search via paragraph style, and can be sorted alphabetically. More info: 

https://helpx.adobe.com/indesign/user-guide.html/indesign/using/creating-table-contents.ug.html

 

Edit: If the name style isn't defined as a Paragraph Style, you'll need to do that first. This can be done via Find/Replace all (1. Highlight one name, go to Paragraph Styles, and give it a name. 2.) Find Helvetica Bold styles. 3. Change style to the created Paragraph Style. 

Votes

Translate

Translate

Report

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 Beginner ,
Oct 28, 2020 Oct 28, 2020

Copy link to clipboard

Copied

Thanks so much, but that won't work (I tried!) as there are multiple entries of the same name/person on different pages that I need to be listed as it would be in an index:

Doe, John   33, 105

Smith, Jane K.   50, 52, 104

I also need them under the "traditional" index headings of A, B, C, etc.

Votes

Translate

Translate

Report

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 ,
Oct 28, 2020 Oct 28, 2020

Copy link to clipboard

Copied

Give this a shot. Note it will add new Page References for already existing items in your index if you already have them. You'll want to start with a fresh index. 

 

 

if (!app.documents[0].indexes[0].isValid) {
   var index = app.documents[0].indexes.add();
} else {
   var index = app.documents[0].indexes[0];
}
app.findTextPreferences = NothingEnum.NOTHING;
//change 'indexName' below to the paragraphstyle to find, leaving the double quotes
app.findTextPreferences.appliedParagraphStyle = "indexName";
var finds = app.documents[0].findText();
for (var i = 0; i < finds.length; i++) {
   try {
      var t = index.topics.add(finds[i].contents);
      t.pageReferences.add(finds[i]);
   } catch(e) {
   }
}
app.findTextPreferences = NothingEnum.NOTHING;

 

 

 

 

Votes

Translate

Translate

Report

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 Beginner ,
Oct 28, 2020 Oct 28, 2020

Copy link to clipboard

Copied

Thank you sooooo much!! It worked like a charm. I think I need to really look into this scripting, though it's truly gibberish to me right now. I know exactly what this one does, but I still can't really see what it says...LOL!

 

Thanks again. My clicking finger thanks you, too.

Votes

Translate

Translate

Report

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 ,
Oct 28, 2020 Oct 28, 2020

Copy link to clipboard

Copied

LATEST

I've been doing it 10+ years and it's still gibberish to me half the time lol. Glad I could help. 

Votes

Translate

Translate

Report

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