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

Indesign Indexing script help

New Here ,
Mar 21, 2020 Mar 21, 2020

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){}
}

TOPICS
Scripting
1.3K
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

correct answers 1 Correct answer

Community Expert , Mar 26, 2020 Mar 26, 2020

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.p
...
Translate
Community Expert ,
Mar 25, 2020 Mar 25, 2020

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

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

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.

            

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

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

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

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.

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