7 Replies Latest reply on Apr 17, 2014 6:40 AM by Kai Rübsamen

    Alphabetically order text frames?


      I have a document with multiple pages, and each page has 5 text frames.

      Is it possible to alphabetically sort those text frames thoughout the document by the heading of each individuall text frame?

        • 1. Re: Alphabetically order text frames?
          Kai Rübsamen Level 4

          I would say yes, but what is the heading? > The first paragraph? If so, only english characters, lower-/uppercase, Umlaute … ? What does sort means for you ? x/y coordinates? Which values?


          Please provide a example before / after.

          • 2. Re: Alphabetically order text frames?
            azanka Level 1

            The booklet is about 10 pages and it comprises of CV's of various persons. Approximately 50 persons, but the number may vary. So I want to be able to add a new person at the last page of the document, and have it automatically sorted in place alphabetically.


            The heading would be the name of the person, first line of the text frame.


            Hope it is clear...

            • 3. Re: Alphabetically order text frames?
              Kai Rübsamen Level 4

              Not really! Where is your screenshot of the final version?


              Does the frames have all the same height and position? I would think, that it is easier to sort the text when all your frames are threaded, than to sort the frames and move them over 10 pages.


              Had some time at the morning. In the screen you can see my current result (frames are sorted, the values show the bounds of the frames). It would be helpful if you provide a idml with those threaded frames.


              Now it is evening here. So the next version will come surely tomorrow.

              Bild 2.png

              • 4. Re: Alphabetically order text frames?
                azanka Level 1

                Sorry, the before version is this:




                the after version is this:




                the text frames are all the same height and position. The text is in Greek.


                Thank you very much!

                • 5. Re: Alphabetically order text frames?
                  Kai Rübsamen Level 4

                  hm, hm. I’m afraid, that my sort-routine will only work with englisch-text at the moment. Since I never did anything with greek text, I have no idea, how greek text can be sorted. But maybe others can dive in here.


                  It is even not clear, how the alternate pictures are created. Please provide your example before/after without the pics as idml. I wil try to write something that will move the frames, after the text is sorted.

                  • 6. Re: Alphabetically order text frames?
                    BEGINNER_X Level 3

                    Hi Kia,


                    Please help for me for the above request:


                    I am just learn myself to complete this, but fail to do it.


                    Below is my coding:



                    var myDoc = app.activeDocument;
                    strArray = new Array();
                    var myStories = app.activeDocument.stories.everyItem().getElements();
                    for(i=myStories.length-1; i>=0; i--)
                        var TF = myStories[i].textContainers;
                        for(k=TF.length-1; k>=0; k--)
                        strArray.push(TF[k].contents + "\t" + TF[k].geometricBounds)
                    var mySort = strArray.sort().join("\r")
                    alert("mySort: " + mySort)
                    struggling here only....


                    Please help to complete this task.


                    My required output is, just sort out text frames one by one in alphabetical order.




                    • 7. Re: Alphabetically order text frames?
                      Kai Rübsamen Level 4

                      I’m not sure, if this is helpful so far, but this is what I have at the moment:



                      var curDoc = app.documents[0];
                      var curPage = curDoc.pages[0];
                      // das Ergebnis der sortierten Liste
                      var sortedTextFrames = getTextFramesAndContent();
                      // den String vorbereiten
                      var msg = "";
                      // eine Schleife durch das Ergebnis
                      for ( var s = 0;  s < sortedTextFrames.length; s++ ) {
                          msg += "Rahmen-ID: " + sortedTextFrames[s][0].id + "\r" +
                          "Erster Absatz: " + sortedTextFrames[s][1] + 
                          "Y-Position: " + sortedTextFrames[s][0].geometricBounds[0] + "\r\r";
                      alert("PageItems sortiert\r" + msg);
                      // gibt alle Textrahmen und deren Inhalt zurück
                      function getTextFramesAndContent() {
                          var list = new Array();
                          // alle Textrahmen der aktuellen Seite
                          var pageTfs = curPage.textFrames;
                          for ( var i = 0; i < pageTfs.length; i++ ) {
                              var curTf = pageTfs[i];
                              // Inhalt des ersten Absatzes im jeweiligen Rahmen
                              firstPara = curTf.paragraphs[0].contents;
                              // den Rahmen u. ersten Absatz in das Array aufnehmen
                              list.push( [curTf, firstPara] );
                          // die Liste seitenweise sortieren
                          list.sort( case_insensitive );
                          return list;
                      function case_insensitive ( a, b ) {
                          return a[1].toLowerCase() > b[1].toLowerCase();