Wednesday, November 16, 2011

Creating a Variable

Variables fall into a category anchored formatted object. Tables and cross references also belong to this group. They are similar to anchored objects (markers) but creating them requires that you specify a format as well as an object type and text location.

In the case of variables, the format is simply the name it is know by in the user interface. You can view a list by using the  Special>Variables command from the FrameMaker menu bar.

The following script adds the Current Date (Long) at the start of the first paragraph in the main flow.

var doc = app.ActiveDoc;
var flow = doc.MainFlowInDoc;
var tFrame = flow.FirstTextFrameInFlow;
var pgf = tFrame.FirstPgf;

function createVariable(doc, pgf, offset, type, format) {
    var tLoc, variable;
    tLoc = new TextLoc(pgf, offset);
    variable = doc.NewAnchoredFormattedObject(type, format, tLoc);
    return 1;

createVariable(doc, pgf, 0, Constants.FO_Var, "Current Date (Long)", "Index");

No comments:

Post a Comment