Wednesday, February 22, 2012

Opening a File with User Interaction

The easiest way to open a file is with SimpleOpen(). This is the analog to SimpleSave() discussed here.

If you do the open interactively, you do not need to know the file's location. You simply let the user locate the proper file.

The following script passes an empty string for the fileName parameter. FrameMaker assumes the file is the last one opened.

var doc;
doc = SimpleOpen("", true);

To open a file without user interaction, you need to pass it is full pathname and false for the second parameter. 

Monday, February 20, 2012

Working with Book Components

You might be tempted to think of FrameMaker books as containing documents. In fact, they contain book components which reference the files that when opened become FrameMaker documents.

To work with all of the documents in a book, you must traverse the list of book components and open each component in turn.

The list of book components is an ordered list. You can start with the FirstComponentInBook. Having found that component, you can use its NextComponentInBook property to find the next book component.

It is also possible to traverse a books components from last to first. In this case you start with LastComponentInBook and use the component's PrevComponentInBook property to move up the list.

The following code snippet shows how you to traverse a book's components from first to last. 

component =book.FirstComponentInBook;
while(component.ObjectValid() ){
    component =  component.NextComponentInBook;

Working with the Active book

The ActiveBook is an exact analog of the ActiveDoc. It refers to the book that has the user focus.

There can be an active book or an active document but not both at the same time. It is also possible that there is neither an active book nor an active document. 

When working with either an active book or an active document, you should check for the possibility that what you are seeking does not exist.

var doc, book;

book  = app.ActiveBook;
if (book.ObjectValid()) {
    Alert("Active book found", Constants.FF_ALERT_CONTINUE_NOTE);
} else {
    doc = app.ActiveDoc;
    if (doc.ObjectValid()) {
        Alert("Active document found", Constants.FF_ALERT_CONTINUE_NOTE);
    } else {
         Alert("No active document or book found", Constants.FF_ALERT_CONTINUE_NOTE);

Saturday, February 4, 2012

Converting Font Style Names to Font Angle Index Values

If your script queries a text property such as font angle, the value you get back is a number and not a name. For example, the following code snippet asks what is the font angle at the text location (tLoc) specified. That information is returned as an integer.

textProp =  doc.GetTextPropVal(tLoc, Constants.FP_FontAngle);
angleIndex = textProp.propVal.ival; //integer value

The integer value angleIndex is an index into an array containing the possible font angle values available in the current FrameMaker session. Use the app (session) property FontAngleNames to get this array of strings.

angleNames = app.FontAngleNames;

Here is that data structure as viewed in the ExtendScript DataBrowser:

The following script converts an angle name to its corresponding index in the angleNames array.

function findAngleIndex(angleName) {
    var angleNames, index;
    angleNames = app.FontAngleNames;
    for (index = 1; index < angleNames.len; index += 1) {
        if (angleNames[index] === angleName) {
    if (index === angleNames.len) {
        index = null;
    return (index);

var index;

index = findAngleIndex("Italic");
Alert(index, Constants.FF_ALERT_CONTINUE_NOTE);

The output is as shown here: