3 Replies Latest reply on May 30, 2012 9:20 PM by Velprakash

    Cut/paste text in a new TextFrame, and place it on the text original position

    Marcos Suárez Level 1

      With this script, the pagraphs with style "_DESTACADOS" are cut and paste in a new TextFrame, but place them in to first page. I need place it on the text original position...

       

      var myDocument = app.activeDocument;

       

      var myRegExp = ".+";

      app.findGrepPreferences = NothingEnum.nothing;

      app.changeGrepPreferences = NothingEnum.nothing;

      app.findGrepPreferences.appliedParagraphStyle = "_DESTACADOS";

      app.findGrepPreferences.findWhat = myRegExp;

      var myFoundItems = myDocument.findGrep(true);

       

      if(myFoundItems.length != 0){

            for(var myCounter = 0; myCounter < myFoundItems.length; myCounter ++){

                myFoundItem = myFoundItems[myCounter];

                myX1 = myFoundItem.characters.item(0).horizontalOffset;

                myY1 = myFoundItem.characters.item(0).baseline;

                myX2 = myX1 + 50;

                myY2 = myY1 + 50;

                 

                  app.selection = myFoundItem;

                      app.cut();

                  myTextFrame = myDocument.textFrames.add();

                  myTextFrame.geometricBounds = [myY1, myX1, myY2, myX2];

                  app.selection = myTextFrame.insertionPoints[0];

                      app.paste(); // Pega el texto del caso encontrado

                  myTextFrame.applyObjectStyle(app.activeDocument.objectStyles.item("_Destacados"), true);           

                  myTextFrame.fit(FitOptions.FRAME_TO_CONTENT);

          }         

      }

       

      THANKS...

        • 1. Re: Cut/paste text in a new TextFrame, and place it on the text original position
          Velprakash Level 1

          Hi Marcos Suárez,

                       If you've xml for the indesign document, u can use the following.

           

          myElement.placeIntoInlineFrame(["8p","6p1"]);

           

          I hope this code is useful in ur script.

          ------------------------------------------------------------------------------------------ ----------

          #include "glue code.jsx"

          var doc = app.activeDocument;

          var myRuleSet = new Array ( new idd)

                    with(doc)

                    {

                              var elements = xmlElements;

                              __processRuleSet(elements.item(0), myRuleSet)

                    }

           

           

           

           

          function idd()

          {

              var newstyle=doc.objectStyles.add("ObjectStyle1");

              newstyle.appliedParagraphStyle="Ap3";

              newstyle.strokeColor="None";

              newstyle.fillColor="None";

                    this.name = "idd"

                    this.xpath = "//title/p2"                    //set this xpath value to the xmltree element which u want to set into frame.

                    this.apply = function(myElement, myRuleProcessor)

                    {

                  var txt=myElement.placeIntoInlineFrame(["8p","6p1"]);

                  txt.fit(FitOptions.frameToContent);

                  txt.applyObjectStyle(newstyle, true);

                }

            return true;

          }

          ------------------------------------------------------------------------------------------ ----------------------

          This will create a textframe around the selected content which u want to do so...

          For more info, refer XMLElement.placeIntoInlineFrame() in Object Model Viewer....

           

          With Regards,

          Vel.

          • 3. Re: Cut/paste text in a new TextFrame, and place it on the text original position
            Velprakash Level 1

            I don't have CS4. I'm having CS5 only. In this it works fine yaar...