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

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...

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.

Similar Messages

Maybe you are looking for

  • Iphoto freezes when trying to make an album or card. what to do?

    I've previously worked with iphoto maing calendars or cards. After a thorough back up of my macbook pro, iphoto has showed repeatedly fails in launching the card, calender or album functions, while working adequate in sharing for example in facebook.

  • Wireless drops on the move of my MacBook Pro 15

    My MacBook Pro 15 (Early 2011, Lion 10.7.3) keeps dropping the wireless connection when I move the computer around the house. There are no issues on the wireless router capacity cause i can still use it from outside the apartment, but it immediately

  • Drag image to a new tab

    In Photoshop CS4, when you drag an image to open it, the program opened in a new tab automatically. Since version CS5, in doing so, the software simply inserts the image on the tab that is already open. There configuring Photoshop CS6 equal to CS4 (w

  • Need information on upgrade project

    Hi all, Could anyone kindly let me know what are the information that i should know regarding an R/3 upgrade project? If anyone has got any document please forward it to [email protected] Awaiting replies. Thanks in advance. Best Regards, Ram.

  • Adding another application to adobe air installer

    Hi, i created an application with adobe air myApp.air and i want to add a driver file in this installer so when the user installing the air application it will also install the needing drivers (it is an application also for windows and mac). is it po