Copy link to clipboard
Copied
Hello,
I wrote a simple script that quickly adds a (first-level) topic and page reference to an index. It seemed to work OK, so I got ambitious and tried to write another script, this time one that reverses the order of a Firstname and Surname where there's a space between them. But now, although the name is duly reversed, it appears in the Index Panel under 'symbol' rather than the first letter of the Surname.
I'd be very grateful for any help.
Thanks, Jeremy
var myDocument = app.activeDocument;
var myIndex = myDocument.indexes.item(0);
var myMarker = app.selection[0];
var myText = myMarker.contents;
var myDialog = app.dialogs.add({name:"Add index entry with range to End of Document",canCancel:true});
with(myDialog){
with(dialogColumns.add()){
var myTextEditField = textEditboxes.add({editContents:myText, minWidth:200});
}
}
var myResult = myDialog.show();
if(myResult == true){
var myIndexTerm = myTextEditField.editContents;
myDialog.destroy();
var myBreak = myIndexTerm.indexOf(' ');
var mySurName = myIndexTerm.slice(myBreak);
var myFirstName = myIndexTerm.slice(0, myBreak);
var myReversedName = mySurName + ", " + myFirstName;
var myTopic = myIndex.topics.add(myReversedName);
myTopic.pageReferences.add(myMarker,PageReferenceType.TO_END_OF_DOCUMENT);
myTopic.name = myReversedName;
}
Jeremy,
The contents of your variable myReversedName start with a space: the problem is in this line:
> var mySurName = myIndexTerm.slice(myBreak);
It catches the space between first and surname. So because your topic name begins with a space it is placed in the symbol section. Apparently, ID has a mechanism to correct that and removes the space when you click the item. Instead, use this:
> var mySurName = myIndexTerm.slice(myBreak+1);
By the way, you could use JavaScript's GREP to switch name and su
...Copy link to clipboard
Copied
And if you double-click on it in the Index Panel to open it up in the Page Reference Options dialog box, then close that dialog box without making any changes at all, it suddenly jumps to the correct place in the Index!
Jeremy (Intermediate-beginner)
Copy link to clipboard
Copied
Jeremy,
The contents of your variable myReversedName start with a space: the problem is in this line:
> var mySurName = myIndexTerm.slice(myBreak);
It catches the space between first and surname. So because your topic name begins with a space it is placed in the symbol section. Apparently, ID has a mechanism to correct that and removes the space when you click the item. Instead, use this:
> var mySurName = myIndexTerm.slice(myBreak+1);
By the way, you could use JavaScript's GREP to switch name and surname:
> myReversedName = myIndexTerm.replace (/([^ ]+) (.+)/, "$2, $1");
Peter
Copy link to clipboard
Copied
Brilliant! -- Problem solved! Thank you very much Peter, once again -- Jeremy
PS: You might be wondering why I want index page ranges that go all the way to the end of the document. It's part of a workaround to get page locators that refer to illustrations appear in the same index as locators that refer to text.
For example, suppose I want a reference to an illustration on p.2, as well as keeping text references to pages 1,2,and 3. I can use GREP on the generated index to turn 1, 2, 2-999, 3 into 1, 2, 2, 3
Copy link to clipboard
Copied
Excellent soultion!
Peter
PS: If you're interested in some index scripting, I recently put on the web some scripts I use for dealing with indexes: http://www.kahrel.plus.com/indesign/lists_indexes.html
Copy link to clipboard
Copied
Yes, those are very helpful, especially the ones for tagging and untagging text. Once you've got something in tagged text form, you can do just about anything with it!
Thanks again --- Jeremy
Find more inspiration, events, and resources on the new Adobe Community
Explore Now