'Hello World': Inserting New Text
/Excerpted from my book FrameScript for Newbies (Copyright [7/17/2007] by Paul Schnall)
Today we will add text to the document, and then we will add a paragraph to a document.
Inserting Text
To insert text use the New Text command. But first:
- Open a document.
- Place the cursor in the document at the location that you want to add the text.
Open the FrameScript editor and type in the command:
New Text 'Hello World';
This command inserts the text that is within the single quotes, at the cursor location.
You can specify a location to place the text (thus bypassing the cursor location) using the TextLoc argument. The command looks like this:
New Text 'Hello World' TextLoc(vTextLoc);
The TexLoc argument is explained in my book Framescript for Newbies.
Inserting New Paragraphs
To write a new paragraph into a document use the New Pgf command. But first
- Open a document.
Open the FrameScript editor and type in the command:
New Pgf NewVar(vNewPgf) PgfFmtName('Body') Text('Hello World');
The NewPgf command has the following arguments (parameters that can be specified in the command).
NewVar assigns the variable name in the parenthesis to the new paragraph.
PgfFmtName assigns the paragraph format that is named within the single quotes to the new paragraph.
Text places the text that is found within the single quotes into the new paragraph.
Note! The paragraph format name must already exist in the catalog, or the script may react unpredictably.
This code will place the new paragraph at the first paragraph in the document and move all of the rest of the paragraphs in the document down one paragraph. It will have the paragraph format of the style ‘Body’. It will have a variable name of vNewPgf.
Note:
All new paragraphs are placed as the first Pgf in the doc if their location is not specified in the command.
The new paragraph can be placed anywhere in the document by using the PrevObject argument. By specifying an object and giving it a variable name you can specify the location of the new Paragraph by adding the PrevObject argument.
The three lines of code below start out specifying the variable vCurrentDoc and assigning it to the active document in the FrameMaker session. The second line of code specifies the variable vPgf and assigns it to the first paragraph in the main flow in the document. Because vPgf is defined in the script I can use it to specify the place to put the new paragraph. The new paragraph will be placed immediately after vPgf.
1) Set vCurrentDoc = ActiveDoc;
2) Set vPgf = vCurrentDoc.MainFlowInDoc.FirstPgfInFlow;
3) New Pgf NewVar(vNewPgf) PrevObject(vPgf) PgfFmtName('Body') Text('Hello World');
The Text of the paragraph ('Hello World') can also be a variable.
Set vCurrentDoc = ActiveDoc;
Set vPgf = vCurrentDoc.MainFlowInDoc.FirstPgfInFlow;
New Pgf NewVar(vNewPgf) PrevObject(vPgf) PgfFmtName('Comment') Text(vPgf.Text);
Note: When using a variable to specify text the variable name is not put in quotes.