Sort a Book?

Viewing 6 reply threads
  • Author
    Posts
    • #85148
      Bryan Colley
      Member

      Is there any way to sort an InDesign Book panel by page number? Maybe a script?

    • #85175
      Ari Singer
      Member

      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!

    • #85179
      Bryan Colley
      Member

      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.

    • #85224
      Peter Kahrel
      Participant

      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

      • #85226
        Ari Singer
        Member

        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

      • #85227
        Ari Singer
        Member

        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”.

    • #85230
      Peter Kahrel
      Participant

      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.

    • #85978
      Bryan Colley
      Member

      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.

    • #85984
      Peter Kahrel
      Participant

      You need to replace ^lt; with the less-than symbol.

      P.

Viewing 6 reply threads
  • You must be logged in to reply to this topic.
>