2 Replies Latest reply on Feb 26, 2015 1:41 AM by K.Daube

    Copy to clipboard

    K.Daube Level 1

      I try to set up a script for this function - but do not get any useful results.

      Obviously my understanding of TextRange is not complete...

      CopyToClipboard ("E:\\_DDDprojects\\FM+EN escript\\FM-11-testfiles\\BibFM-collected.rtf");
      function CopyToClipboard (theText) {
      // - create a textframe with a paragraph on the first masterpage (which always exist)
        var masterPage, textFrame, pgf, textLoc, PT = 65536;  
        var oTRange = new TextRange, oTexts;
        var doc = app.ActiveDoc;
        masterPage = doc.FirstMasterPageInDoc;          // Get the first master page in the document.  
        textFrame = doc.NewTextFrame (masterPage.PageFrame); // Add a temporary text frame to the master page.   
        textFrame.Width  = 480 * PT;  
        pgf = textFrame.FirstPgf;  
        textLoc = new TextLoc (pgf, 0);  
        doc.AddText (textLoc, theText);                 // write the string into this paragraph
        oTexts = pgf.GetText (Constants.FTI_String);    // select it 
        oTLoc1.obj = pgf;
        oTLoc2.obj = pgf;
        for ( i = 0; i < oTexts.length; i++ ) {
          if (oTexts[i].dataType == Constants.FTI_String ) {
            oTLoc1.offset = oTexts[i].offset;
            oTLoc2.offset = oTexts[i].offset + oTexts[i].sdata.length;
            oTRange.beg = oTLoc1;
            oTRange.end = oTLoc2;
            oDoc.TextSelection = oTRange;
        doc.Copy (0);                                   // copy selection to clipboard not interactive
      alert ("something to see?");
        textFrame.Delete ();                            // delete the text frame 

      The text frame is placed either on the master page or the body page - depending on which i have switched to - strange.

      The alert at the end shows that the text is placed, but my TextRange construct has no effect: the clipboard contains old stuff.

        • 1. Re: Copy to clipboard
          K.Daube Level 1

          My "The text frame is placed either on the master page ..." is a misconception. Of course anything placed on the master page shows up on the body page... (well, I really become old or tired).

          • 2. Re: Copy to clipboard
            K.Daube Level 1

            Thanks to Debra Herman's blog post I have now found out:

            Lines 15 to 26 replaced by

              tRange.beg.obj = pgf;                           // select it
              tRange.beg.offset = 0;
              tRange.end.obj = pgf;
              tRange.end.offset = theString.length;
              doc.TextSelection = tRange; 

            get the correct function.