6 Replies Latest reply on Mar 2, 2012 2:48 AM by Karl Z

    Is it possible to sort textframes in alphabetical order?

    Karl Z

      Hi,

       

      I have a large number of separate text frames with text startsing with a number.

       

      Is it possible to sort the text frames i alphabetical / numeric order either in y or z?

       

      Scripts available that I've found sort paragraphs, but since my text frames contains several paragraphs that's not an option.

       

      InDesign CS5, MacOS X.

       

      So, help much appreciated.

       

      /K

        • 1. Re: Is it possible to sort textframes in alphabetical order?
          [Jongware] Most Valuable Participant

          Can you post an image showing the current Before and desired After state?

           

          (... trying to visualize "sort on z" ... move them to the previous/next page, perhaps. In a printed book that would surely count as the 'z' order?)

          • 2. Re: Is it possible to sort textframes in alphabetical order?
            Karl Z Level 1

            Z would be sorted "on top" of each other from top to bottom. But as I think of it Z won't work after all, so lets forget that one.

             

            After sorting them I use the "MergeTextFrames_ID.jsx" to get the text into one text frame.

            Keep in mind that there migt be as many as 40 text frames (or more) som manual sorting is really time-consuming.

             

            /K

            sort-sample.png

            • 3. Re: Is it possible to sort textframes in alphabetical order?
              [Jongware] Most Valuable Participant

              That took me a few minutes

               

              Sorting 'on contents' is easy, but then the text order inside the frames as set would be correct, but not the order of the frames themselves. The top frame on your screen may not be "the first one" according to the order of creation.

              So you also have to re-sort the text frame location, top to bottom and left to right. I do this by first sorting the frames into the correct location, so the "first" frame is actually the first one on the page, then the next one etc.

              Then I sort the contents on the first word and move the frames around into their sorted order.

               

              I do this quick 'n dirty: by moving their geometric bounds around. Thus it's possible I place a large text into a small 'original' frame (actually I don't move the text around) and it might get overset. But this way nothing else on the screen changes.

               

              If you want the frames aligned and spaced out as in your "below" image, you could do that before running my script.

               

              Is this what you were looking for?

               

              list = app.selection;
              org_order = [];
              for (i=0; i<list.length; i++)
              org_order[i] = list[i].geometricBounds;
              org_order.sort (function(a,b) {
              if (a[0] == b[0]) return a[1] - b[1];
              return a[0] - b[0];
              });
              list.sort ( function(a, b) {
              return parseInt(a.texts[0].words[0].contents) - parseInt(b.texts[0].words[0].contents);
              });
              for (i=0; i<org_order.length; i++)
              {
              list[i].geometricBounds = org_order[i];
              }
              
              • 4. Re: Is it possible to sort textframes in alphabetical order?
                Karl Z Level 1

                Thanks!

                 

                This just might be it... but,  see,  I'm not that good at reading code like this...

                I need a script that i can run from ID scripts panel. Can I just copy this code and save it as... .jsx (?) and test it out?

                 

                /K

                • 5. Re: Is it possible to sort textframes in alphabetical order?
                  [Jongware] Most Valuable Participant

                  But of course. Yeah it's Javascript, so save as "sort_textframes.jsx".

                   

                  Double-check after running that Merge Text Frames script that everything is still in the right order, it's always possible one of these scripts does something unexpected.

                  • 6. Re: Is it possible to sort textframes in alphabetical order?
                    Karl Z Level 1

                    I must say, I am very impressed! Works like a charm! And super quick too!

                     

                    Saved it. Tried it. Laughed! Still big smile on my face!

                     

                    Thank you ever so much!

                     

                     

                    /K