ExtendScript of the Week: Keyboard Simulation in FrameMaker via Fcodes

Fcodes could be called as JIT automation for FrameMaker. I.e. with minimal effort, one could automate FM tasks with it. If you are a starter it could be very effective in automating some of the small tasks – in a breeze!

Fcodes are small programmatic commands/constants that can automatically simulate user input within FrameMaker. It is relatively (very) easier to automate small tasks via Fcodes than using the real API functions. It’s not that I am proposing ‘not’ to use API functions, but it is just an alternative for starters who would like to automate ‘small tasks in small time’. Fcodes are not new, they exist since very early versions of FM. With ExtendScript, they have become a little bit easier to use.

Fcodes are actually hexadecimal codes that specify individual user actions in FM. There are 1000+ Fcodes available with FM that a user may use. The entire list of Fcodes can be found in <FDK installation>\include\fcodes.h (and FDK can be downloaded from http://www.adobe.com/devnet/framemaker.html).

There are 2 ways to use Fcodes:

via Extendscript

or via FDK Client.

We can use the Fcodes in FM Extendscript (.jsx) or the FM API (.dll). The function Fcodes() in Extendscript / F_ApiFcodes() in API respectively can be used to execute fcodes command. The fcodes command works like this: it sends an array of Fcodes to FrameMaker which is executed in FM, one by one (as if the user performed the action manually).

Method

File Type

Function Used

Extendscript

.jsx

Fcodes()

FDK API

Compiled as .dll

F_ApiFcodes()

The example below describes some extremely simple code on how to create ExtendScript-based Fcode clients for simulating user actions in FrameMaker.

Simple steps:

In FM10, File -> Script -> New Script (script editor opens)

copy paste just few lines of code from e.g.1 or 2.

Simply click Execute or F5.

Example 1: Writing Text in the Document via script

Fcodes can be used to simply write in a document or a dialog automatically. The 2-line example below shows how easily one could write in the document via Fcodes in ExtendScript.

We have a scenario where we have written a document that has been checked for spellings but still has some keywords that show as misspelled. The user would like to learn all those words (add them to user dictionary). By executing an Fcode we may add all those keywords to our user dictionary. Here’s how to do it (this example adds the first misspelled word to the user dictionary):

We have a scenario where we need to set the paragraph line spacing to a particular value. We just need to traverse to the paragraph(s) and execute this Fcode. Important: This type of script that involves dialog focus needs to be run from within FM only. (via File -> Script -> Catalog/Run [a saved script])