2 Replies Latest reply on Nov 14, 2017 12:15 AM by Trevorׅ

    Organise Selected Pages Alphabetically Indesign CC

    m.ah

      I have organised an indesign document into different sections each section has around 20 pages that need to be sorted alphabetically by the title of the page.

      Is there any way to do this?

      Ive used this script so far, However I need a way to be able to sort alphabetically each section of the document. For example- Pages 2-15 then Pages 18-40

       

      Any help would be great!

       

      // Script to sort Pages according to alphabetical order of their top TextFrames contents  // by Trevor (www.creative-scripts.com [coming soon]) custom and readymade scripts for InDesign  // http://forums.adobe.com/thread/1405293?tstart=0  // see also http://forums.adobe.com/thread/1082984?tstart=0 for a better workflow    app.doScript("aToZPageSort()", ScriptLanguage.javascript, undefined, UndoModes.FAST_ENTIRE_SCRIPT, "Sort Pages By top text contents");  function aToZPageSort () {      var doc =  app.documents[0],            myPageIndex = [],            l = doc.pages.length,            topFrameIndex = z= 0, pageFramesTops, i, topFrameHeight, topFrame;      while (l--) {          pageFramesTops = doc.pages[l].textFrames.everyItem().getElements().slice(0);          n = i = pageFramesTops && pageFramesTops.length;           if (!i) continue;          while (n--) pageFramesTops[n] = pageFramesTops[n].geometricBounds[0]; // for some reason when one trys to get the geometricBounds[0] from teh everyItems without the elements it return y1, x1 and not just y1 ?-)          topFrameHeight = pageFramesTops[0];          topFrame = doc.pages[l].textFrames[0];          for (var n = 0; n< i ; n ++) {              if (pageFramesTops[n] < topFrameHeight) {                  topFrameHeight = pageFramesTops[n];                   topFrame = doc.pages[l].textFrames[n];              }          }          myPageIndex [z++] = {page: topFrame.parentPage, contents: topFrame.contents.toLowerCase()}      }      myPageIndex.sort (function (a,b) {return (a.contents.toLowerCase() > b.contents.toLowerCase())});        l = myPageIndex.length;      while (l--) myPageIndex[l].page.move (LocationOptions.AT_BEGINNING);  } 
        • 1. Re: Organise Selected Pages Alphabetically Indesign CC
          schiuma24 Level 1

          var doc = app.activeDocument;

          var pages = doc.pages;

          var p = pages.length;

          var docarray = [];

           

          while (p--) {

           

              var pagearray = [];

           

              allFrames(pages[p], pagearray);

           

              if (pagearray.length != 0) {

           

                  pagearray.sort(

           

                      function(a, b) { return a.geometricBounds[0] > b.geometricBounds[0]});

           

                  docarray.push(pagearray[0])

              }

          }

           

          docarray.sort(function(a, b) {return a.words[0].contents.toLowerCase() > b.words[0].contents.toLowerCase()});

           

          var d = docarray.length;

           

          while (d--) {

           

               var c = docarray[d].parentPage.name;

           

               doc.pages.item(c).move(LocationOptions.AT_BEGINNING)

          }

           

          function allFrames(source, array) {

           

              var frames = source.pageItems;

              var t = frames.length

           

              while (t--) {

           

                  if (frames[t].getElements()[0].constructor.name == 'TextFrame') {

           

                      array.push(frames[t]);

           

                  }

           

                  if (frames[t].getElements()[0].constructor.name == 'Group') {

           

                      allFrames(frames[t], array)

                  }

              }

           

          }

          • 2. Re: Organise Selected Pages Alphabetically Indesign CC
            Trevorׅ Adobe Community Professional

            I think this is what you are after

             

            HTH

             

            Trevor

             

            // Script to sort Pages according to alphabetical order of their top TextFrames contents  
            // by Trevor (www.creative-scripts.com) custom and readymade scripts for InDesign  
            // https://forums.adobe.com/thread/2173486
            // see also http://forums.adobe.com/thread/1082984?tstart=0 for a better workflow  
            // jshint undef:true, unused: true
            
            
            aToZPageSort(2,5); // change this!
            
            function aToZPageSort(startPage /*1 is page 1*/ , endPage) {
                var wrapper;
                wrapper = function(startPage, endPage) {
                    var doc, i, l, myPageIndex, pageFramesTops, topFrame, topFrameHeight, topFrameIndex, z;
                    doc = app.documents[0];
                    myPageIndex = [];
                    l = doc.pages.length;
                    topFrameIndex = z = 0;
                    startPage = (startPage) ? startPage - 1 : 0;
                    endPage = (endPage) ? endPage - 1 : l - 1;
                    for (l = endPage; l >= startPage; l--) {
                        pageFramesTops = doc.pages[l].textFrames.everyItem().getElements().slice(0);
                        n = i = pageFramesTops && pageFramesTops.length;
                        if (!i) continue;
                        while (n--) pageFramesTops[n] = pageFramesTops[n].geometricBounds[0]; // for some reason when one trys to get the geometricBounds[0] from teh everyItems without the elements it return y1, x1 and not just y1 ?-)  
                        topFrameHeight = pageFramesTops[0];
                        topFrame = doc.pages[l].textFrames[0];
                        for (var n = 0; n < i; n++) {
                            if (pageFramesTops[n] < topFrameHeight) {
                                topFrameHeight = pageFramesTops[n];
                                topFrame = doc.pages[l].textFrames[n];
                            }
                        }
            
                        myPageIndex[z++] = { page: topFrame.parentPage, contents: topFrame.contents.toLowerCase() };
                    }
                    myPageIndex.sort(function(a, b) { return (a.contents.toLowerCase() > b.contents.toLowerCase()); });
            
                    l = myPageIndex.length;
                    while (l--) myPageIndex[l].page.move(LocationOptions.BEFORE, doc.pages[startPage]);
                };
                app.doScript("wrapper(" + startPage + "," + endPage + ")", ScriptLanguage.javascript, undefined, UndoModes.FAST_ENTIRE_SCRIPT, "Sort Pages By top text contents");
            }