Highlighted

Indesign Indexing script help

New Here ,
Mar 21, 2020

Copy link to clipboard

Copied

Can someone tell me what lines to add to script so that it will fill in Topic levels 3 & 4 of index entry. Currently script fills Level 1 with "Steamers" and Level 2 with selected text in document. Would like it to fill Level 3 with "Schedules" and Level 4 with "1950"

#target indesign
var debug=false;
try{
main();
}catch(e){log(e)};
function main()
{
var myDocument = app.activeDocument;
if(!myDocument.indexes.length) myDocument.indexes.add();
var myIndex = myDocument.indexes[0];
var myTopics = myIndex.topics;

var currSelection = app.selection[0];
log(currSelection.constructor.name);
if (currSelection.constructor.name!="Text") {alert("Please make text selection"); return;}

var myTopic=myTopics.itemByName("Steamers");

try{
myTopic.id;
}catch(e){
myTopic=myTopics.add("Steamers");
}

var currTopic = myTopic.topics.add(currSelection.contents);

currTopic.pageReferences.add(currSelection,PageReferenceType.TO_END_OF_STORY);


//myTopics.add("Steamers");
}

function log(obj)
{
if (debug)
try{ $.writeln("------");
$.writeln(obj + " - "+obj.toSource());
$.writeln("------");
}catch(e){}
}

Most Valuable Participant
Correct answer by _Jongware_ | Most Valuable Participant

Manan is right, but you have to add the page reference to that last created Topic:

 

 

var currSelection = app.selection[0];
if (!currSelection.hasOwnProperty("baseline"))
{
	alert("Please make text selection"); return;
}

var myTopic = myTopics.itemByName("Steamers");
if (!myTopic.isValid)
{
	myTopic=myTopics.add("Steamers");
}

var currTopic = myTopic.topics.add(currSelection.contents);
scheduleTopic = currTopic.topics.add("Schedules");
yearTopic = scheduleTopic.topics.add("1950");
yearTopic.pageReferences.add(currSelection,PageReferenceType.TO_END_OF_STORY);

 

 

which results in what you want:

 

dummy placeholder Steamer namedummy placeholder Steamer name

 

(I'd also suggest using the old trick of checking a selection for having "baseline". The constructor of a text selection may also be something like "... Character, InsertionPoint, Line, Paragraph, TextColumn, TextStyleRange, and Word", depending on what you selected.)

Topics

Scripting

Views

252

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

Indesign Indexing script help

New Here ,
Mar 21, 2020

Copy link to clipboard

Copied

Can someone tell me what lines to add to script so that it will fill in Topic levels 3 & 4 of index entry. Currently script fills Level 1 with "Steamers" and Level 2 with selected text in document. Would like it to fill Level 3 with "Schedules" and Level 4 with "1950"

#target indesign
var debug=false;
try{
main();
}catch(e){log(e)};
function main()
{
var myDocument = app.activeDocument;
if(!myDocument.indexes.length) myDocument.indexes.add();
var myIndex = myDocument.indexes[0];
var myTopics = myIndex.topics;

var currSelection = app.selection[0];
log(currSelection.constructor.name);
if (currSelection.constructor.name!="Text") {alert("Please make text selection"); return;}

var myTopic=myTopics.itemByName("Steamers");

try{
myTopic.id;
}catch(e){
myTopic=myTopics.add("Steamers");
}

var currTopic = myTopic.topics.add(currSelection.contents);

currTopic.pageReferences.add(currSelection,PageReferenceType.TO_END_OF_STORY);


//myTopics.add("Steamers");
}

function log(obj)
{
if (debug)
try{ $.writeln("------");
$.writeln(obj + " - "+obj.toSource());
$.writeln("------");
}catch(e){}
}

Most Valuable Participant
Correct answer by _Jongware_ | Most Valuable Participant

Manan is right, but you have to add the page reference to that last created Topic:

 

 

var currSelection = app.selection[0];
if (!currSelection.hasOwnProperty("baseline"))
{
	alert("Please make text selection"); return;
}

var myTopic = myTopics.itemByName("Steamers");
if (!myTopic.isValid)
{
	myTopic=myTopics.add("Steamers");
}

var currTopic = myTopic.topics.add(currSelection.contents);
scheduleTopic = currTopic.topics.add("Schedules");
yearTopic = scheduleTopic.topics.add("1950");
yearTopic.pageReferences.add(currSelection,PageReferenceType.TO_END_OF_STORY);

 

 

which results in what you want:

 

dummy placeholder Steamer namedummy placeholder Steamer name

 

(I'd also suggest using the old trick of checking a selection for having "baseline". The constructor of a text selection may also be something like "... Character, InsertionPoint, Line, Paragraph, TextColumn, TextStyleRange, and Word", depending on what you selected.)

Topics

Scripting

Views

253

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
Adobe Community Professional ,
Mar 25, 2020

Copy link to clipboard

Copied

Hi Connie,

 

Disclaimer i have not worked with Indexes at all so i am not very sure if i understood your query correctly. Could you try by adding the following code after the line where you use the pageReferences.add method

currTopic.topics.add("Schedules").topics.add("1950")

 

Let me know how it goes.

 

-Manan

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...
New Here ,
Mar 26, 2020

Copy link to clipboard

Copied

I am likely not explaning well. Current script results in index entry as below where Steamers is the entry and Dakota is a sub-entry (a name of a steamer). Adding your line makes no difference and gives below result.

Steamers
    Dakota 33

I'd like to get an entry like as below when I run the script. In the final index, there would be Steamers as the entry and under that would be a list of steamers and under each steamer would be various sub-headings. (Once I had the script that would create below entry, I could create versions of it for each year in the book, for example.)

Steamers

   Dakota

       Schedules
           1950    33

Thanks for your assistance.

            

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...
Most Valuable Participant ,
Mar 26, 2020

Copy link to clipboard

Copied

Manan is right, but you have to add the page reference to that last created Topic:

 

 

var currSelection = app.selection[0];
if (!currSelection.hasOwnProperty("baseline"))
{
	alert("Please make text selection"); return;
}

var myTopic = myTopics.itemByName("Steamers");
if (!myTopic.isValid)
{
	myTopic=myTopics.add("Steamers");
}

var currTopic = myTopic.topics.add(currSelection.contents);
scheduleTopic = currTopic.topics.add("Schedules");
yearTopic = scheduleTopic.topics.add("1950");
yearTopic.pageReferences.add(currSelection,PageReferenceType.TO_END_OF_STORY);

 

 

which results in what you want:

 

dummy placeholder Steamer namedummy placeholder Steamer name

 

(I'd also suggest using the old trick of checking a selection for having "baseline". The constructor of a text selection may also be something like "... Character, InsertionPoint, Line, Paragraph, TextColumn, TextStyleRange, and Word", depending on what you selected.)

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...
New Here ,
Mar 28, 2020

Copy link to clipboard

Copied

Thank you. That works like magic! It will save me hours of work.

One question - how do I mark your answer as correct? I must be blind but I don't see how. Thanks.

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...