5 Replies Latest reply on Jun 4, 2010 8:20 AM by GD_lewis

    Split Paragraph Into Multiple Text Frames

    GD_lewis

      Hi everyone,

       

      Was wondering if you guys could help me out. I'm trying to automate the process of taking each line in a paragraph (separated by forced line breaks) and giving it its own text frame, so that I can move them around independently. This is best illustrated in the screenshot attached.

       

      Screen shot 2010-06-03 at 17.59.50.png

       

      Do you think this is possible via a script?

       

      Thank you in advance!

      Lewis

       

      Message was edited by: GD_lewis

        • 1. Re: Split Paragraph Into Multiple Text Frames
          [Jongware] Most Valuable Participant

          Possible? Sure -- but it depends on how closely you want the slivers match the original text layout.

           

          This script is based on my CopyCutter; it splits a text frame into its component lines.

           

          //DESCRIPTION:CopyCutter 2 — Cut your Copy into Slivers
          // Jongware, 3-Jun-2010
          
          if (app.selection.length == 1 && app.selection[0] instanceof TextFrame)
          {
               f = app.selection[0];
               for (i=0; i<f.lines.length; i++)
               {
                    newf = f.duplicate();
                    newf.texts[0].remove();
                    f.lines[i].duplicate (LocationOptions.BEFORE,newf.lines[0]);
                    if (i > 0)
                         top = f.lines[i-1].baseline;
                    else
                         top = f.geometricBounds[0];
                    bot = f.lines[i].baseline;
                    newf.geometricBounds = [ top, f.geometricBounds[1], bot, f.geometricBounds[3] ];
               }
               f.remove();
          }
           
          

          • 2. Re: Split Paragraph Into Multiple Text Frames
            lewis_cooper Level 1

            [Jongware], as ever... you've hit the nail on the head.

             

            Thank you!

            • 3. Re: Split Paragraph Into Multiple Text Frames
              GD_lewis Level 1

              I'm going to stop asking if things are possible or not, as with you most things seem to be!

               

              Are you able to extend the copy cutter script to help me achieve what is being shown here: http://cl.ly/f8bac5b91811b35fec3e ?

               

              The diagram is quite descriptive but one thing it doesn't show is that I'd like it to cut the selected text as opposed to just copying it.

               

              Thanks in advance,

              Lewis

              • 4. Re: Split Paragraph Into Multiple Text Frames
                [Jongware] Most Valuable Participant

                Okay, that image helped a lot in providing context!

                 

                Does this work for you? Select a number of words; these will be split by its regular spaces (I use a slightly different GREP, hope it's of no consequence), then moved into frames of their own alongside your current text frame.

                Then it creates a new text frame and inserts tomorrow's lottery numbers ... oh wait, I'm still working on that.

                 

                Don't try running this from inside a table or a footnote or really anything at all more complicated than a simple text frame. It'll most likely do something but I'm not sure what.

                 

                if (app.selection.length == 1 && app.selection[0].hasOwnProperty("baseline") && app.selection[0].length > 1)
                {
                 app.selection[0].insertionPoints[0].contents = "\r";
                 app.selection[0].insertionPoints[-1].contents = "\r";
                 app.findGrepPreferences = null;
                 app.changeGrepPreferences = null;
                 app.findGrepPreferences.findWhat = " +";
                 app.changeGrepPreferences.changeTo = "\\r";
                 app.selection[0].changeGrep();
                 p = app.selection[0].parentTextFrames[0];
                 lh = (p.lines[-1].baseline - p.lines[0].baseline) / (p.lines.length-1);
                 top = app.selection[0].lines[0].baseline - lh;
                 while (app.selection[0].length > 0)
                 {
                  f = app.activeDocument.layoutWindows[0].activePage.textFrames.add ({geometricBounds:[top, p.geometricBounds[3]+2*lh, top+lh, 2*(lh+p.geometricBounds[3])-p.geometricBounds[1] ]});
                  app.selection[0].lines[0].move (LocationOptions.AFTER, f.texts[0]);
                  top += lh;
                 }
                 app.selection[0].insertionPoints[-1].contents = "";
                } else
                 alert ("please select some text to shred");
                
                • 5. Re: Split Paragraph Into Multiple Text Frames
                  GD_lewis Level 1

                  Thank you so much [Jongware]! You're a legend.

                   

                  7739_notworthy.gif