9 Replies Latest reply on Jun 15, 2013 4:10 AM by lewis_cooper

    Modification Needed to Jongware's CopyCutter

    lewis_cooper Level 1

      Hi all,

       

      I've tried and failed to do this myself so I'm hoping that someone or even Jongware himself can help me out. I'd previously asked this question: http://forums.adobe.com/message/2865783#2865783 and I ended up with a modified version of Jongware's CopyCutter.

       

      Unfortunately the formatting of my document has changed so I need to modify the script to take these changes in to account. Could someone please help me?

       

       

       

      Here is how my copy currently looks:

       

      Screen Shot 2013-06-13 at 10.39.13.png

       

      This is what I want to select and apply the script to:

       

      Screen Shot 2013-06-13 at 10.34.17.png

       

       

      And this is the result I'm hoping to get (Note the missing \n\n at the beginning too):

       

      Screen Shot 2013-06-13 at 10.36.17.png

       

      Bonus points: I'd quite like the resulting text boxes to be given an object style that I could define.

       

       

       

      And for reference here is the script that I currently have (link at beginning of post my provide more context):

       

       

      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");
      
      
        • 1. Re: Modification Needed to Jongware's CopyCutter
          Jump_Over Level 5

          Hi,

           

          if (app.selection.length == 1 && app.selection[0].hasOwnProperty("baseline") && app.selection[0].length > 1)
          {
              mObjSt = app.activeDocument.objectStyles.item("your oSt_name");
              app.selection[0].insertionPoints[0].contents = "\r";
              app.findGrepPreferences = app.changeGrepPreferences = null;
              app.findGrepPreferences.findWhat = "(\\u)(?=~s)";
              app.changeGrepPreferences.changeTo = "\\r\$1";
              app.selection[0].changeGrep();
              app.findGrepPreferences.findWhat = "\\n\\n\\r";
              app.changeGrepPreferences.changeTo = "";
              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;
                f.appliedObjectStyle = mObjSt;
               }
               p.characters[-1].contents = "";
          } else
           alert ("please select some text to shred");
          

           

          did it?

          (edit objectStyle name in 2nd line)

           

          Jarek

          1 person found this helpful
          • 2. Re: Modification Needed to Jongware's CopyCutter
            lewis_cooper Level 1

            Hi, thank you very much for your help. Unfortunately this error message was returned:

             

            Screen Shot 2013-06-13 at 14.33.36.png

            • 3. Re: Modification Needed to Jongware's CopyCutter
              Jump_Over Level 5

              Hi,

               

              It works on my empty 1-frame doc...

               

              before line 13 insert alert to check an error source:

              alert(p.isValid);
              alert(p.lines[-1].baseline);
              

               

              what they show?

               

              Jarek

              1 person found this helpful
              • 4. Re: Modification Needed to Jongware's CopyCutter
                lewis_cooper Level 1

                Forgive me, it is now working! I forgot to select the first two \n\n before executing the script .

                 

                The result gives me this:

                Screen Shot 2013-06-13 at 15.38.46.png

                How can I have the "\r" removed from the end of each line?

                 

                Thank you by the way!

                • 5. Re: Modification Needed to Jongware's CopyCutter
                  Jump_Over Level 5

                  Hi,

                   

                  last line inside a while loop:

                   

                  if (f.lines[-1].contents.indexOf("\r") != -1) f.characters[-1].contents = "";
                  

                   

                  Jarek

                  • 6. Re: Modification Needed to Jongware's CopyCutter
                    lewis_cooper Level 1

                    Hmmmm, doesn't seem to work for me. Although I'm not sure I understand 'while loop'.

                     

                    I did it like this:

                     

                     

                    if (app.selection.length == 1 && app.selection[0].hasOwnProperty("baseline") && app.selection[0].length > 1)
                    {
                        mObjSt = app.activeDocument.objectStyles.item("Colour Label Grey");
                        app.selection[0].insertionPoints[0].contents = "\r";
                        app.findGrepPreferences = app.changeGrepPreferences = null;
                        app.findGrepPreferences.findWhat = "(\\u)(?=~s)";
                        app.changeGrepPreferences.changeTo = "\\r\$1";
                        app.selection[0].changeGrep();
                        app.findGrepPreferences.findWhat = "\\n\\n\\r";
                        app.changeGrepPreferences.changeTo = "";
                        app.selection[0].changeGrep();
                        app.findGrepPreferences.findWhat = ", ";
                        app.changeGrepPreferences.changeTo = "";
                        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;
                          f.appliedObjectStyle = mObjSt;
                         }
                         p.characters[-1].contents = "";
                    } else
                     alert ("please select some text to shred");
                     if (f.lines[-1].contents.indexOf("\r") != -1) f.characters[-1].contents = "";
                    
                    
                    • 7. Re: Modification Needed to Jongware's CopyCutter
                      Jump_Over Level 5

                      Hi,

                       

                      I ment this part of code:

                      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;
                           f.appliedObjectStyle = mObjSt;
                           if (f.lines[-1].contents.indexOf("\r") != -1) f.characters[-1].contents = "";
                           }
                      

                       

                      last line added here

                       

                      Jarek

                      • 8. Re: Modification Needed to Jongware's CopyCutter
                        lewis_cooper Level 1

                        Hi Jarek,

                         

                        Thank you very much, this is now quite simply perfect! I really appreciate your help with this.

                         

                        Lewis

                        • 9. Re: Modification Needed to Jongware's CopyCutter
                          lewis_cooper Level 1

                          Hi Jarek,

                           

                          Sorry to dig this up again! The script is working great but if I try to execute it without extending the bottom of the text frame down, I get an error message.

                           

                          For example;

                           

                          If execute the script when the text frame is 'tight' to the copy like this:

                           

                          Screen Shot 2013-06-15 at 12.04.49.png

                           

                          I get this error message:

                           

                          Screen Shot 2013-06-14 at 17.34.35.png

                           

                          However, if I drag the base of the text frame down to give more space like this:

                           

                          Screen Shot 2013-06-15 at 12.05.22.png

                           

                          The script executes without a problem. Is there something I can do to stop this??