FrameScript for Newbies

Excerpted from my book FrameScript for Newbies Copyright [7/17/2007] by Paul Schnall

In general FrameScript is used to perform complicated tasks on large books or on whole document sets. Scripts can also be written to perform tasks on the document level, these range from manipulating paragraphs to tables. Large complicated scripts are usually written by professional scriptwriters, but with a little help any technical writer can acquire the skills needed to start writing scripts quickly and easily.

FrameScript is an object oriented scripting language. Everything in FrameMaker is either an object or an object property. In FrameMaker object properties are characteristics of the objects, for example, text can have a property that the font color is green. FrameMaker objects can be all encompassing to include all of the books and documents open in a session (a session is anything that occurs after you start FrameMaker until you close FrameMaker) down to the color of a font or the background color in a table cell. In general each object and its corresponding properties can be accessed and manipulated, except for read only properties. By accessing and manipulating these objects and properties it is possible to change:

  • text
  • markers
  • font sizes
  • colors

Also almost any property of a:

  • document
  • paragraph
  • table
  • character

The figure below shows part of the object hierarchy of FrameMaker.

Figure 1. Sample of the FrameMaker Hierarchy.

Variables

Variables are names given to objects or properties, like names for the children in a class. Variables are arbitrary names the writer chooses. I usually precede them with the letter v to make them stand out in the script.

For example:

You want to run a script that searches each paragraph for a specific word. You can assign a variable (I use the name vPgf) to the first paragraph in the document or the first paragraph in the main flow of the document.

Set VPgf = vCurrentDoc.MainFlowInDoc.FirstPgfInFlow;

Once the variable is assigned to the first object in the flow or document, if the property “Next ---- in doc ” or “Next----in Flow” exists in the Reference guide, then you can just keep reassigning the variable the to the next whatever in the doc until you reach the end.

Set VPgf = VPgf.NextPgfInFlow;

Objects other than paragraphs also have an associated Next command. For example tables, markers, and graphics, also have this command.

Set Command

The set command assigns a variable to an object or an object property.

1) Set vCurrentDoc = ActiveDoc;

This command assigns the variable vCurrentDoc to the object ActiveDoc. ActiveDoc is the open document in the FrameMaker window (this is an object). With the Variable vCurrentDoc set to the ActiveDoc, I can now specify objects deeper in the hierarchy (from the document to a paragraph to the paragraph format to the font color) using this variable. See ‎Figure 1 for the hierarchy from document to paragraph format.

2) Set VPgf = vCurrentDoc.MainFlowInDoc.FirstPgfInFlow;

Since the vCurrentDoc has already been specified, I can now drill down through the hierarchy, through the main flow in the document, to the first paragraph in the flow.

These two lines at the beginning of a script tell FrameScript to run the script on the currently active document and it sets the script to start at the first paragraph of the main flow in the document.

Note: Starting with the first paragraph in a document and proceeding to the NextPgfInDoc does not go through the document paragraph by paragraph in the order in which the paragraphs are written, whereas MainFlowInDoc.NextPgfInFlow does.

Note: There are all sorts of tables and text related to reference pages and master pages preceding the actual document, and your scripts can run through these first if you use the First---in Doc command.