Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Copy to clipboard

Community Expert ,
Feb 25, 2015 Feb 25, 2015

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.dataType == Constants.FTI_String ) {
      oTLoc1.offset = oTexts.offset;
      oTLoc2.offset = oTexts.offset + oTexts.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.

TOPICS
Scripting
908
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 26, 2015 Feb 26, 2015

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.

Translate
Community Expert ,
Feb 26, 2015 Feb 26, 2015

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 26, 2015 Feb 26, 2015
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines