Highlighted

Straightforward script to add entry using paragraph style

Community Beginner ,
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.

Adobe Community Professional
Correct answer by brianp311 | Adobe Community Professional

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;

 

 

 

 

TOPICS
Scripting

Views

76

Likes

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

Straightforward script to add entry using paragraph style

Community Beginner ,
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.

Adobe Community Professional
Correct answer by brianp311 | Adobe Community Professional

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;

 

 

 

 

TOPICS
Scripting

Views

77

Likes

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
Oct 28, 2020 0
Adobe Community Professional ,
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. 

Likes

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
Reply
Loading...
Oct 28, 2020 1
Community Beginner ,
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.

Likes

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
Reply
Loading...
Oct 28, 2020 0
Adobe Community Professional ,
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;

 

 

 

 

Likes

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
Reply
Loading...
Oct 28, 2020 2
Community Beginner ,
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.

Likes

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
Reply
Loading...
Oct 28, 2020 0
Adobe Community Professional ,
Oct 28, 2020

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Oct 28, 2020 1