Sunday, October 16, 2011

Getting and Setting a Paragraph Property

It is an easy change to have the count paragraphs script update the paragraph instead. In this example, all paragraph text is underlined.  All you need to know to make this change is the name of the Underlining paragraph property and its possible values:
  • Constants.FV_CB_NO_UNDERLINE
  • Constants.FV_CB_SINGLE_UNDERLINE
  • Constants.FV_CB_DOUBLE_UNDERLINE
  • Constants.FV_CB_NUMERIC_UNDERLINE
Here is the updated code:

var doc = app.ActiveDoc;

var mainflow = doc.MainFlowInDoc;
var tframe = mainflow.FirstTextFrameInFlow;
var pgf = tframe.FirstPgf;
while (pgf.ObjectValid()) {
    pgf.Underlining = Constants.FV_CB_SINGLE_UNDERLINE;
    pgf = pgf.NextPgfInFlow;
    }

Note: The change just made was to the paragraph and not the paragraph format. There is an asterisk next to each format name in the status area at the lower left as shown below. This reflects the fact that the format has been over-ridden.


While you are unlikely to want to add underlining to a paragraph, perhaps you might want to remove it. To do so, first determine if the paragraph is underlined and then change the property setting as desired.

var doc = app.ActiveDoc;

var mainflow = doc.MainFlowInDoc;
var tframe = mainflow.FirstTextFrameInFlow;
var pgf = tframe.FirstPgf;
while (pgf.ObjectValid()) {
    if ( pgf.Underlining = Constants.FV_CB_SINGLE_UNDERLINE)
        pgf.Underlining = Constants.FV_CB_NO_UNDERLINE;
    pgf = pgf.NextPgfInFlow;
    }

Note: This script removes any underlining not applied with a character format. Underlining that stems from the application of a character format remains as is.

No comments:

Post a Comment