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

Reversed name appears in index under 'Symbol' rather than 'A','B','C'...

Enthusiast ,
Apr 09, 2009 Apr 09, 2009

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;

}

TOPICS
Scripting
975
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 , Apr 09, 2009 Apr 09, 2009

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

...
Translate
Enthusiast ,
Apr 09, 2009 Apr 09, 2009

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)

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 ,
Apr 09, 2009 Apr 09, 2009

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

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
Enthusiast ,
Apr 09, 2009 Apr 09, 2009

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

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 ,
Apr 09, 2009 Apr 09, 2009

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

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
Enthusiast ,
Apr 09, 2009 Apr 09, 2009
LATEST

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

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