Knowing Where You Are

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

It is always good to know where you are, this is also true in scripting. Most FrameMaker objects have a text location or text range property. This property tells you the coordinates of the object. Then, these coordinates can be used to place other object relative to this location. For example, if you have the text range of a paragraph, then you can specify a new text location. The new text location can be anywhere within this text range. The text location can be used to add text at that point.

Text Range

Many FrameMaker objects have the property TextRange. This is the place within the document that identifies the location of an object. For example the title may have a Text Range as specified in the figure below. Along with the text range property there are also two other properties;

  • the starting point of the object
  • the endpoint of the object.

These can be specified using the dot notation

  • vPgf.TextRange.Begin
  • vPgf.TextRange.End.

Figure 1. TextRange

The TextRange can be obtained using the dot notation. For example:

1) Set vPgf = vCurrentDoc.MainFlowInDoc.FirstPgfInFlow;

2) Set vPgfTextRange = vPgf.TextRange;

Line 2 sets the variable name vPgfTextRange equal to the text range of the first paragraph in the main flow of the document.

The TextRange property specifies the range of a FrameMaker object or the range of a section of text, using the text location at the beginning and the text location at the end of the FrameMaker object or text. The most useful of these objects is the paragraph. The paragraph object has a property TextRange. You can then assign a variable to either the beginning or End of the TextRange by using:

Set vTextRangeStartingLoc = vpgf.TextRange.Begin;

Or

Set vTextRangeEndingLoc = vpgf.TextRange.End;

TextLoc

A Text Location can be specified using:

Set vTextLoc = vPgf.TextRange.Begin;

This code sets a variable to the location of the beginning of the paragraph vPgf.

A TextLoc can also specify any position in the paragraph by specifying an offset from the beginning or by specifying the end or an offset back from the end of the TextRange. This offset specifies the number of characters and/or spaces to move forwards or backwards (using a negative number).

Figure 2. New TextLoc using the end of the object with a negative offset.

Figure 3. Adding Text

New TextLoc

This command allows you to specify a location in the document and assign it a variable name. This is useful when you want to insert objects into the document. New TextLoc NewVar(vTextLoc) Object(vPgf) Offset(ObjEndOffset-1);

The command above:

  • creates a new text location
  • assigns the new location the variable name vTextLoc

It takes the location from the TextRange property of the object vPgf. Offset then counts places from either the beginning or the end of the TextRange. In the example above it counts back one space from the end of the object TextRange. The TextLoc is limited to a single location and cannot be a range.

Variables as their name imply can change. During the course of running the script the variable vPgf may continuously be reassigned. For example in a Loop through the paragraphs the variable vPgf will, with each iteration of the loop, be reassigned to the next paragraph in the document. It is important to understand that the paragraph that is associated with the variable vPgf can change as the script runs. Using If statements can identify which paragraph is assigned the variable vPgf.

In general, when looping through a document the first thing you want to do inside the loop is to put an If statement that will be able to identify the paragraphs you are looking for.

Loop For Each paragraph.

If the paragraph contains the text "Boy, is it cold out!"
The If command returns a value of true or false. If you know the that the if statement is true you can do something with the paragraph at this point. You also know that the variable vPgf is assigned to this particular paragraph. And that vPgf.TextRange.End is the location of the end of this paragraph.

// Add text at the text location.

New Text TextLoc(vTextLoc) ' I wish I had a coat. ';

End the if statement

Continue on looping through the paragraphs of the document.

 

Useful Information

  • Job Listings (visible to only members)

  • Employee Benefits

  • Other Sites and Resources

    Survey Reporting

    Q2 2010 Survey Results

    Requires access rights

    Employee Salaries (18 pp)

    Freelance Writer Rates (11 pp)

    Q4/09 Copy Editor Rates (9 pp)


    Columns on Elephant

    Translatable but Debatable

    Each month, Mark L. Levinson presents one hard-to-translate Hebrew word at a time for discussion.

    Of Mice and Keyboard Shortcuts

    Michael Cohen will teach us practical shortcuts that save us time and make our lives easier.

    The Why of Style

    Mark L. Levinson examines the big and little factors that make writing effective.

    Broken Bell Education in Israel

    David Siegel looks at the problems in education in Israel and discusses what can be done.

    Jonathan's Tool Bar & Grill

    Jonathan Plutchok identifies free or inexpensive utilities or plug-ins that save time, increase productivity, improve your computing environment, perform a task you otherwise couldn't do... or is just too much fun to ignore. This column has grown into its own blog at http://jonathanstoolbar.blogspot.com where you can find new issues every week.

    It's in The Script

    Paul Schnall teaches us about the power of FrameScript and how to use it.

    Do it Yourself

    Did you ever wonder what was inside a PC, laptop, or other microcomputer system? Michael Cohen teaches us what's inside and how to configure and build our own.

    Coaching for Success

    Dr. Tal discusses the principles of professional coaching, focusing on resiliency.

    Hunters and Gatherers

    Eric Gluch looks at modern marketing.

    Moving to Chelm

    Esther Shira Stepansky takes us on a humorous adventure in the modern day land of Chelm as we look at some of the challenges of making aliyah and finding work in Israel. Making aliyah is supposed to be the fulfillment of my of your Jewish identity, so why does Israel make it so difficult?

    Why am I a Tech Writer?

    By Michael Altman

    Life as a Tech Writer

    By Mumpy

    Building Bridges (in Hebrew)

    Dr. Zaidel discusses another aspect of mediation within the framework of Israel's court-approved Alternative Dispute Resolution (ADR) process.

    Don't Forget

    Hezy Asher teaches us how to improve our memory.

    World of Podcasting

    Tom Johnson's podcast episodes, provide tips on recording presentations, and other podcasting related news and events.

    Effective Management ניהול אפקטיבי

    By Eitan Reuveni

    Scribblin' With Steph

    By Stephanie Freid

    Life in Northern Israel

    By multiple authors

    Life on the Southern Front of Israel

    By Israel Ivri

    Event Summaries

    Summaries of events held by Elephant and other organizations throughout the Israeli technical/marcom community.