25 Replies Latest reply on Mar 15, 2017 7:59 AM by Obi-wan Kenobi

# Repeated Volume Numbers in Index

I have a three volume book, whose pages are in the form I:1, I:2...II:1, II:2...III:1, III:2... My problem is the index to the three volumes, which looks like this: topic I:23, I: 34, I: 245, I:450, II: 345, II: 451, III: 24, III: 45 and so forth. Can I somehow remove these repeated volume numbers so that I get a normal (and much less cluttered) multi-volume index, namely "I: 23, 34, 245, 450; II: 345, 451; III: 24, 45"?

• ###### 1. Re: Repeated Volume Numbers in Index

I believe this can be done with InDesign script (.jsx file)

For example, this GREP will search for Roman digits:

`(\\<(M{0,3}(D?C{0,3}|C[DM])(L?X{0,3}|X[LC])(V?I{0,3}))\\>)`

and the script should check Roman and Arab digit sequences and remove the second and following Roman digits in the row...

this GREP will find entire sequence - "I:23, I: 34, I: 245, I:450, II: 345, II: 451, III: 24, III: 45"

```(((\\<(M{0,3}(D?C{0,3}|C[DM])(L?X{0,3}|X[LC])(V?I{0,3}))\\>):\\s?\\d+(,\\s)?))+
```

from what was found - search

```(((\\<(M{0,3}(D?C{0,3}|C[DM])(L?X{0,3}|X[LC])(V?I{0,3}))\\>):\\s?
```

and remove 2nd and following occurrences

• ###### 2. Re: Repeated Volume Numbers in Index

When you say "remove 2nd and following occurrences," do you mean that I have to remove these manually? There are thousands of them and I am looking for a way to remove them automatically. For example, I can remove the "I:" after every first occurrence by doing a find on ", I:" and changing all to ", " so that, for example, American Revolution  I:120, I:124, I:132, II:39, II:59, II:73, II:346, III:52 becomes American Revolution  I:120, 124, 132, II:39, II:59, II:73, II:346, III:52 but I can't figure out how to get rid of the second and further occurrences of "II:" and "III:"

If the first volume entries were separated from the second volume entries by a semi-colon (or anything else) instead of a comma, I could change all ", II:" to ", " but with nothing but commas, doing this would remove the first occurrence of "II" and "III" in all my entries.as well.

Any thoughts?

• ###### 3. Re: Repeated Volume Numbers in Index

just try this script and let me know if it works.

code if far from perfect, but it seems to be working...

• ###### 4. Re: Repeated Volume Numbers in Index

When I put the script in the scripts folder and double click on it, I get a dialog box that says "Select text to sort and try again!" If I then select the index (or any text from it), I get the same message.

• ###### 5. Re: Repeated Volume Numbers in Index

strange, it works on my side...

I made some changes so it should now show more specific error message - redownload script from the same location, select text frame or text itself and try to run script one more time.

if it still does not work - you may ask in this scripting forum InDesign Scripting

• ###### 6. Re: Repeated Volume Numbers in Index

I need a new link to Dropbox; the old one no longer works since the old script has been deleted.

• ###### 8. Re: Repeated Volume Numbers in Index

This time I get the message, "Java Script Error" #89867, "Error string: the default engine 'main' cannot be deleted," and a little later, "line 65."

• ###### 9. Re: Repeated Volume Numbers in Index

sorry, I don't know why this is not working for you, try to ask at this forum InDesign Scripting

• ###### 10. Re: Repeated Volume Numbers in Index

Thanks for your help. I put this question on the InDesign Scripting Scripting board last Tuesday but have not had any responses. Do you think I should keep waiting, or do you have any other suggestions on where I might look for help?

• ###### 12. Re: Repeated Volume Numbers in Index

I dont know if this helps, i have not tested this script myself.

Try to replace

```exit(e);
```

in the script Multi-volume Index.jsx (rows 33 and 65) with:

```alert("Error: "+ e.message);
exit();
```
• ###### 13. Re: Repeated Volume Numbers in Index

When I try the revised script I get JavaScript error #2 (problem in line 36) "Error String: whereToSearch is undefined"

• ###### 14. Re: Repeated Volume Numbers in Index

Peter

Just a small clarification. My change only allows you to get a message that tells you something about what has gone wrong.

Take a look at this part in your script, that tries to define "whereToSearch":

```    switch(app.selection[0].constructor.name){
case "InsertionPoint":
case "TextFrame":
whereToSearch = app.selection[0].parentStory;
break;
case "Paragraph":
case "Text":
case "Line":
whereToSearch = app.selection[0];
default:
whereToSearch = app.activeDocument;
}
```

To mee it looks like you have to make a selection in your document before you run the script.

• ###### 15. Re: Repeated Volume Numbers in Index

Yes, thanks. I did forget to select the text.

Now I get the message "Null is not an object"

• ###### 16. Re: Repeated Volume Numbers in Index

I made some changes, now everything should be ok - have a try and let me know if it works

right now - if nothing selected - changes will be applied to all text frames in the opened / active document, if only one text frame selected - changes will be applied only to selected text frame, and finally - if you select some text - changes will be applied only for this selection.

if you still have some problems - can you share the document you are working with? Or at least one page...

• ###### 17. Re: Repeated Volume Numbers in Index

We must be getting closer. The latest version works perfectly on 5-10 lines of he index, but if I try to do more, it has no effect on any of it. If I then go back and do a few of the same lines, it works.

Thanks for working on this.

• ###### 18. Re: Repeated Volume Numbers in Index

this is strange, maybe if there are too many instances - all you need is wait a bit longer?

check this update but I'm not sure if this will help Dropbox - Multi-volume Index.jsx

need to check with the real problematic file - in my test example if successfully process 24+ text frames with different sequences

• ###### 19. Re: Repeated Volume Numbers in Index

This script also works fine with perhaps 10-15 lines but when I try to do more, or do a text frame, I get the message Error Number: 27 Error String: stack overrun

Is it possible for me to send you the original index?

• ###### 20. Re: Repeated Volume Numbers in Index

yes, you should be able to send me a direct message here or you can send me email > oleh.melnyk at gmail.com if you are not able to share it publically (via dropbox or any other services) so other forum members could also help with the problem

• ###### 21. Re: Repeated Volume Numbers in Index

Here is the index. I eliminated the extra vol. 1 volume numbers without needing a script. Now I am trying to remove the extra vol. 2 and 3 volume numbers. http://https://www.dropbox.com/s/f3fdv88xc9gmrgb/Index.indd?dl=0

• ###### 23. Re: Repeated Volume Numbers in Index

Dropbox - Multi-volume Index.jsx Script updated, now it works, at least with the file you sent me, but this index list is long - there are over 5 000 instances that need to be checked/sorted and formatted the way you like, so it takes time... in my computer with core i5 processor (4 cores, 3.5 GHz), 20 Gb ram, and Windows 10 it took me 2.5 minutes to complete (you need to wait till you get message "Done!" or some error).

So I suggest splitting this index into the smaller pieces - run script on them and then when, and only when everything is ready - merge them down.

UPD: in some cases, it might look like the script has skipped some instances - most likely this means that problem is related to the source - it didn't match the pattern for some cases - you already edited something or made a typo, or changed something intentionally... The script should not try to read your mind and guess why some lines didn't match the pattern. So it's up to you to make sure everything is consistent and correct in the source. But anyway I believe that what my script does is much better than doing everything manually.

• ###### 24. Re: Repeated Volume Numbers in Index

It worked! It took a few passes, but then picked up most of the repeated volume numbers.

Thank you so much for continuing to work on this script!

(Now that I know how to use scripts, maybe I'll use them more often in Indesign.

In any case, I am grateful for all your help,

Peter Ray

• ###### 25. Re: Repeated Volume Numbers in Index

Hi,

Take a look at:  Code to be evaluated! [017] Double loop! …  [Post#5]

(^/)