Invalid text location
Dear all,
Int he following script I want to place a variable at a particular position in a paragraph.
Obviously my method to define a TextLocation in line 11 is wrong. Line 26is never executed and hence no variable inserted.
TestInsertVariable ();
function TestInsertVariable () {
var paraText = "Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts."
var oDoc = app.ActiveDoc, sValue, sVarName, oTextLoc, oPgf;
if(oDoc.ObjectValid()) {
oPgf = oDoc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;
oTextLoc = new TextLoc(oPgf, 0);
oDoc.AddText(oTextLoc, paraText); // create a paragraph
oTextLoc = new TextLoc(oPgf, 17); // arbitrary place
sVarName = "GugusVariable";
sValue = "--- Anything I want to see in my variable ---";
InsertVariable (oDoc, oTextLoc, sVarName, sValue);
} else {
alert ("Document does not exist or is invalid");
}
} //--- end TestInsertVariable
function InsertVariable (oDoc, oTextLoc, sVarName, sValue) { //=== Insert variable at location ====
var oVar;
$.bp(true);
oVar = oDoc.NewAnchoredFormattedVar (sVarName, oTextLoc);
if (oVar.ObjectValid ()) {
oVar.Fmt = sValue;
}
} //--- end InsertVariable
Do I need the detour with TextSelection, etc. ?

