Copy link to clipboard
Copied
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.
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.
Copy link to clipboard
Copied
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).
Copy link to clipboard
Copied
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.