Tuesday, October 18, 2011

Updating a Paragraph Format

This post looks at how to update an existing paragraph format and then, having made several updates, apply those updates to all paragraphs that use that format.

As the paragraph format exists, the script uses its name to get its object:
var pgfFmt = doc.GetNamedObject(Constants.FO_PgfFmt, "Body");

The script then changes several properties of the format:
  • The paragraph is set to be auto-numbered.
  • An autonumbering string is defined. (This is the definition string.)
  • Capitalization is set to upper case.
  • Change bars are turned on.
These changes only update the paragraph format. To apply the changes to all of the existing paragraph formats, it helps to think about how an end user would accomplish this task. (File>Import Formats ... from the current document into itself with check Paragraph Formats and remove Other Format/Layout Overrides chosen.)

In ExtendScript, this translates to the SimpleImportFormats method with the following parameters:
var err = doc.SimpleImportFormats(doc, Constants.FF_UFF_PGF|
Constants.FF_UFF_REMOVE_EXCEPTION);


IMPORTANT: The FrameMaker ESTK documentation calls for ORing the constants. The FDK documentation calls for a bitwise or and, based on my observations, that appears to be correct here as well.

Use the Portrait template in your testing or any other template that has a Body paragraph format defined. Your file must be saved or the import of formats cannot succeed. 

var doc = app.ActiveDoc;
var tframe = doc.MainFlowInDoc.FirstTextFrameInFlow;

var pgfFmt = doc.GetNamedObject(Constants.FO_PgfFmt, "Body");
if (pgfFmt.ObjectValid) {
    pgfFmt.PgfIsAutoNum = true;
    pgfFmt.AutoNumString= "<n+>. ";
    pgfFmt.Capitalization = Constants.FV_CAPITAL_CASE_UPPER;
    pgfFmt.ChangeBar = true;
   
    var formatFlags = Constants.FF_UFF_PGF | Constants.FF_UFF_REMOVE_EXCEPTIONS;
    doc.SimpleImportFormats (doc, formatFlags);
}
else
    Err("Format not found");





No comments:

Post a Comment