Sort a Book?
Learn / Forums / General InDesign Topics / Sort a Book?
- This topic has 9 replies, 3 voices, and was last updated 7 years, 10 months ago by Peter Kahrel.
-
AuthorPosts
-
-
May 24, 2016 at 11:16 am #85148Bryan ColleyMember
Is there any way to sort an InDesign Book panel by page number? Maybe a script?
-
May 24, 2016 at 5:19 pm #85175Ari SingerMember
I might be able to write a script for that (if needed), but I first have to understand better what you’re trying to acheive. Thanks!
-
May 24, 2016 at 6:00 pm #85179Bryan ColleyMember
If I have 5 documents in a book that all have different page numbers, but they’re not sequential, I’d like to be able to sort the documents in the book by page number. So pages 10, 38, 2, 15, and 12 would be ordered page 2, 10, 12, 15, and 38 so that when I print the book it’s in the right order.
We publish a journal and the ad pages aren’t in the book so there’s lots of page gaps between documents, and we shuffle them around a lot so I’m always having to resort things manually.
-
May 25, 2016 at 3:11 pm #85224Peter KahrelParticipant
Here’s a script that sorts book files by their (first) page number.
(function () { var list = []; var docs = app.books[0].bookContents; for (var i = 0; i < docs.length; i++) { list.push ({name: docs[i].name, firstPage: Number(docs[i].documentPageRange.replace(/-\d+/,''))}); } list.sort (function (a,b) {return a.firstPage - b.firstPage}) for (i = list.length-1; i >= 0; i--) { docs.item(list[i].name).move (LocationOptions.AT_BEGINNING); } }
Peter
-
May 25, 2016 at 5:14 pm #85226Ari SingerMember
Peter, I’m afraid you left out the closing parentheses, as well as the immediate call to invoke it.
I fixed it for you:
(function () { var list = []; var docs = app.books[0].bookContents; for (var i = 0; i < docs.length; i++) { list.push ({name: docs[i].name, firstPage: Number(docs[i].documentPageRange.replace(/-\d+/,''))}); } list.sort (function (a,b) {return a.firstPage - b.firstPage}) for (i = list.length-1; i >= 0; i--) { docs.item(list[i].name).move (LocationOptions.AT_BEGINNING); } })()
Ari
-
May 25, 2016 at 5:49 pm #85227Ari SingerMember
One more thing, this script will not work if the Page Numbering View settings (found in the General pane of the InDesign preferences) is set to “Absolute Numbering”.
But it’s probably not an issue anyway because the default is “Section Numbering”.
-
-
May 26, 2016 at 12:15 am #85230Peter KahrelParticipant
Thanks for fixing the brace and parentheses, Ari. Cursed copy gremlins!
As to the page numbering setting, that must be by section because otherwise Bryan’s workflow doesn’t work at all.P.
-
May 26, 2016 at 7:10 am #85232Ari SingerMember
You’re right.
-
-
June 22, 2016 at 9:53 am #85978Bryan ColleyMember
I’m finally getting around to testing out this script.
I put it into InDesign with a book of files and when I run the script I get this error:
Error Number: 25
Error String: Expected: )
Line 4
Source: for (var i = 0; i ^lt; docs.length;i++) {
Offending Text: ;I’m not so great with Javascript so I’m not sure what the problem is. I only know Applescript.
-
June 22, 2016 at 11:24 am #85984Peter KahrelParticipant
You need to replace ^lt; with the less-than symbol.
P.
-
-
AuthorPosts
- You must be logged in to reply to this topic.