Saturday, October 29, 2011

Adding Text at a Location in Text

Just as user typing appears at the insertion point, a script adds text at a text location.

A text location consists of an object identifier (either an paragraph or a text line) and an offset from the start of that object.

The following example inserts text at the beginning of the first paragraph in the active document.

var doc = app.ActiveDoc;

var mainflow = doc.MainFlowInDoc;
var tframe = mainflow.FirstTextFrameInFlow;
var pgf = tframe.FirstPgf;

var tLoc= new TextLoc(); //create the text location object
tLoc.obj = pgf; //make it a paragraph
tLoc.offset = 0; // insert at the start of the paragraph
doc.AddText (tLoc, "Izzy ");

If you start out with the following document











and run the script, you get









If you change the text location to 3 (tLoc.offset = 3; ), you get the following:




No comments:

Post a Comment