Copy link to clipboard
Copied
Hi,
I let Indesign generate an index, using two paragraphstyles:
First: Artist
Second: title
De index shows the artists alphabetically, but the pagenumbers are sort of random.
How can the index let the titles of the same artist from low to high? Or beter: titles from the same artist summed up and ascending? Although I can do that manualy.
How strange -- the script looks for the paragragraph style TOC Artiest, which according to your screenshot is used for the artist.
Never mind, here's a more fail-safe method: place the cursor in any of the artist names and run this version of the script:
app.findGrepPreferences = null;
app.findGrepPreferences.appliedParagraphStyle =
app.selection[0].appliedParagraphStyle;
f = app.selection[0].parentStory.findGrep();
for (i = f.length-1; i >= 1; i--) {
if (f[i].contents == f[i-1].conten
...
Ugh -- what a dumb bug. When you don't sort the TOC by artist, everything comes out as expected -- sorted by page number. But sorting the level-1 entries (artists) messes up the order of the level-2 entries (titles). So you can sort a TOC correctly only if there is just one level.
In your case you should really mark up the artists and titles with index markers, so you get exactly what you're after. You's need one or two scripts to mark up the document, but that's a one-off. Adding index marker
...Copy link to clipboard
Copied
This looks more like a table of contents than in index. In an index you'd expect the titles to be subtopics of the artist, but then the artist's name would appear once with all their titles indented below it.
> the pagenumbers are sort of random
What do you mean by this? What would you expect? Can you show a screenshot of how you want your TOC/index to appear?
Copy link to clipboard
Copied
Oooh, I think you're right. It's a TOC but I want an index, looking like this:
Can you tell me how to do that?
Copy link to clipboard
Copied
It depends on how your document was marked up, it looks like a TOC, but then it's strange that the titles aren't in page order. Probably the TOC style was set up incorrectly. Can you show a screenshot of the TOC style window showing the TOC style used for generating the TOC?
That leaves the duplicate artist names to be removed, but that's a fairly simple script.
Copy link to clipboard
Copied
It is definitely a TOC. If there is a script to remove the duplicates, that would we wonderful (there are 4800 unique titles).
This is de style of te TOC:
Copy link to clipboard
Copied
Select one of the frames of the TOC's story or click somewhere in the TOC, then run this script:
app.findGrepPreferences = null;
app.findGrepPreferences.appliedParagraphStyle =
app.activeDocument.paragraphStyles.item('TOC Artiest');
f = app.selection[0].parentStory.findGrep();
for (i = f.length-1; i >= 1; i--) {
if (f[i].contents == f[i-1].contents) {
f[i].remove();
}
}
Copy link to clipboard
Copied
Sorry, got a error when running the script
Copy link to clipboard
Copied
How strange -- the script looks for the paragragraph style TOC Artiest, which according to your screenshot is used for the artist.
Never mind, here's a more fail-safe method: place the cursor in any of the artist names and run this version of the script:
app.findGrepPreferences = null;
app.findGrepPreferences.appliedParagraphStyle =
app.selection[0].appliedParagraphStyle;
f = app.selection[0].parentStory.findGrep();
for (i = f.length-1; i >= 1; i--) {
if (f[i].contents == f[i-1].contents) {
f[i].remove();
}
}
Copy link to clipboard
Copied
Wow! That worked. Thank you very much!!
Just one more thing: the pagenumbers are not from low to high. Any idea how to fix that?
Copy link to clipboard
Copied
The titles should be ordered by page number, it being a TOC. Can you show your TOC style window with the title style selected? Or maybe send your document (or part of it, looks like a big one).
A script can be done to sort the titles, but it's not as near-trivial as the other script, and those titles should be sorted by InDesign.
Copy link to clipboard
Copied
The document is indeed very large.
TOC style Title:
Copy link to clipboard
Copied
You use the same style (TOC Artiest) for the Artist and Title entries. Maybethat's the problem. Maybe if you create a new style for the TOC title entries and apply that in the TOC style, the titles are sorted correctly by page number. (Though when I try a sample with the same style for artist and title the titles are still sorted correctly.)
Is the page numbering in the document correct? It's hard to see what can go wrong with the page numbering, but who knows.
Maybe you can send a sample with the first 30 pages or so, and if you don't want to put it on the forum you can send it to pkahrel@gmail.com
Puzzled in Valencia,
P.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Ugh -- what a dumb bug. When you don't sort the TOC by artist, everything comes out as expected -- sorted by page number. But sorting the level-1 entries (artists) messes up the order of the level-2 entries (titles). So you can sort a TOC correctly only if there is just one level.
In your case you should really mark up the artists and titles with index markers, so you get exactly what you're after. You's need one or two scripts to mark up the document, but that's a one-off. Adding index markers is simple enough, but because artiist and title are in separate frames it's not so straightforward. Can be done though.
For now, though, sticking to the TOC is simpler. Like before, use the earlier script to remove duplicate artist names. Then use the script, below, to sort the titles by page number. Place the cursor in any title, then run the script.
One thing I noticed just now is that titles are sorted by page number only: if there are two or more titles on the same page, those titles aren't sorted automatically.
// Place the cursor in a paragraph
// on whose name you want to sort the list
(function () {
app.findGrepPreferences = null;
app.findGrepPreferences.appliedParagraphStyle =
app.selection[0].appliedParagraphStyle;
var story = app.selection[0].parentStory;
if (story.characters[-1].contents != '\r') {
story.insertionPoints[-1].contents = '\r';
}
var temp = app.documents[0].textFrames.add ({
geometricBounds: [0, 0, '50mm', '50mm'],
});
function sortBlock (block) {
var i;
var index = block.index;
var a = [];
var p = block.paragraphs.everyItem().getElements();
for (i = 0; i < p.length; i++) {
a.push ({
text: p[i],
key: Number (p[i].contents.match (/\d+(?=\r)/)[0]),
});
}
a.sort (function (a, b) {return a.key - b.key});
for (i = 0; i < p.length; i++) {
a[i].text.duplicate (
LocationOptions.AT_END,
temp.parentStory
);
}
block.remove();
temp.parentStory.move (
LocationOptions.AFTER,
story.insertionPoints[index]
);
}
var titles = app.selection[0].parentStory.findGrep();
for (var i = titles.length-1; i >= 0; i--) {
if (titles.length > 1) {
sortBlock (titles[i]);
}
}
while (story.characters[-1].contents == '\r') {
story.characters[-1].contents = '';
}
temp.remove();
}());
Copy link to clipboard
Copied
It really works! All pagenumbers are nice and clean ordered from low to high now.
I'm very grateful. It saves me a lot of time.....
Thank you very much!