3 Replies Latest reply on May 25, 2011 10:33 AM by GD_lewis

    Quick (I think) Script Tweak Needed

    GD_lewis

      Hi everyone,

       

      I've got the following script:

       

       

      if (app.selection.length == 1 && app.selection[0].hasOwnProperty("baseline") && app.selection[0].length > 1)
      {
       app.selection[0].insertionPoints[0].contents = "";
       app.selection[0].insertionPoints[-1].contents = "";
       app.findGrepPreferences = null;
       app.changeGrepPreferences = null;
       app.findGrepPreferences.findWhat = "\n";
       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");
      
       
      

       

       

      That performs this action (screen shot): http://www.cl.ly/3o2R3Q3A3J0K1Q3D3h3z

       

      As you can see, I am unfortunately left with residual paragraph breaks at the end of each colour name. Is there anyway I can add:

       

       app.findGrepPreferences.findWhat = "\r";
       app.changeGrepPreferences.changeTo = "";
      

       

      Somewhere in my original script in order to clean things up afterwards?

       

      And for extra bonus points... can I have something that executes a Fit Frame to Content command on those three resulting text frames?

       

      Thank you!

        • 1. Re: Quick (I think) Script Tweak Needed
          Peter Kahrel Adobe Community Professional & MVP

          I don't think these two lines:

           

          app.selection[0].insertionPoints[0].contents = "";
          app.selection[0].insertionPoints[-1].contents = "";

           

          do anything at all -- see what happens if you leave them out. How these two:

           

          app.findGrepPreferences.findWhat = "\n";

          app.changeGrepPreferences.changeTo = "\\r";

           

          work I don't understand, because you got your escaping mixed up:

           

          app.findGrepPreferences.findWhat = "\\n";
          app.changeGrepPreferences.changeTo = "\r";

           

          To remove spurious returns, use this:

           

          app.findGrepPreferences.findWhat = "\\r\\r+";
          app.changeGrepPreferences.changeTo = "\r";

           

          As to fittinf a frame to its contents, use this:

           

           

          myTextFrame.fit(FitOptions.frameToContent);

           

          Peter

          1 person found this helpful
          • 2. Re: Quick (I think) Script Tweak Needed
            GD_lewis Level 1

            Thank you very much Peter! The paragraph break removal works a treat.

             

            But I'm not sure where in my script I'm supposed to add:

             

             myTextFrame.fit(FitOptions.frameToContent);
            

             

            so that it's the last thing that gets executed. Can you point me in the right direction?

             

            Lewis

            • 3. Re: Quick (I think) Script Tweak Needed
              GD_lewis Level 1

              Hi again Peter,

               

              I've just looked at that script again and realised that actually it's not working as well as I thought.

               

              if (app.selection.length == 1 && app.selection[0].hasOwnProperty("baseline") && app.selection[0].length > 1)
              {
               app.findGrepPreferences = null;
               app.changeGrepPreferences = null;
               app.findGrepPreferences.findWhat = "\\r\\r+";
               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");
              
               
              

               

               

              Here's a another screenshot of the new results: http://cl.ly/323R0L2C1a2p403O092A

               

              As you can see, instead I am now left with Forced Line Breaks in place of the of the Paragraph Ends (except the last colour name). Also, the paragraph break between styles in the main box has been lost, which messes up the styles.

               

              Do you think there is a way around all this?

               

              Thank you so much in advance.