Extendscript of the week: Keyboard simulation in FM via Fcodes

Monday, February 27 2012 @ 12:53 PM, By Amit Agarwal

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. Its 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’. F-codes are not new, they exist since very early version of FM. With extendscript they have become little more 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:

  1. via Extendscript
  2. 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 working below describes some extremely simple code on how to create Fcode (extendscript based) clients for simulating user-actions in FrameMaker.

Simple steps:

  1. In FM10, File -> Script -> New Script (script editor opens)
  2. copy paste just few lines of code from e.g.1 or 2.
  3. Simply click Execute or F5.

E.g. 1. Writing Text in the Document via script

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

FcodeList = new Array(FCodes.CSR_TOP, 'HI!', Fcodes.HIGH_WORD_PREV, FCodes.TXT_BOLD); //Fcodes
Fcodes(FcodeList); // Fcode Execution

E.g. 2. Add Misspelled words (Squigglied words) to User Dictionary via script

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):

FcodeList_Pers = new Array(FCodes.KBD_CHECKDOC, FCodes.KBD_ADDUSRDICT); //Fcodes
for (i=1; i<=1; i++) // Loop -> 1 could be made n
{
 Fcodes(FcodeList_Pers); //Execute Fcode
}

E.g. 3. Setting custom value in Paragraph Line Spacing dialog via scriptWe 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])

FcodeList = new Array(FCodes.PGF_LINE_SPACE, FCodes.START_DIALOG, FCodes.KBD_ItemNextLogical, '4','0', FCodes.KBD_RETURN, FCodes.END_DIALOG); // Fcodes
Fcodes(FcodeList); // FCodes Execution

Description of the Fcodes as used in E.g. 3:

  • FCodes.PGF_LINE_SPACE opens “Paragraph Line Spacing” dialog
  • FCodes.START_DIALOG denotes the dialog is in use
  • FCodes.KBD_ItemNextLogical denotes SINGLE TAB in the dialog (i.e. pressing a TAB key in dialog takes the focus to the text field)
  • ‘4’,’0′ writes the value 40 instead of 42. (Since the text field 42 is already selected after pressing the tab)
  • FCodes.KBD_RETURN performs the “Set” (also closes the dialog)
  • FCodes.END_DIALOG denotes the dialog is not in use now
  • Fcodes(FcodeList) statement executes the above sequence of Fcodes

With this information and examples we should be able to write simple snippets for automating our tasks in FM. For reference the entire list of fcodes is being attached.

Important Points:

  • Do a manual traversal of the workflow before executing Fcodes.
  • Each Fcode need to be preceded by “FCodes.”
  • Any Fcode client during automatic execution needs to gain the focus so it is imperative we stop the mouse & keyboard activity when the Fcode based client runs.
  • The .jsx file containing Fcodes on dialogs should be executed from the “Script Explorer” ONLY
  • When a dialog launches another dialog use END_DIALOG for previous START_DIALOG for the newly launched dialog.
  • There is an existing issue with Fcodes not working properly over the Book (Bug# 3099221)

Do let us know your story with Fcodes for FrameMaker!

~Amit Agarwal

FM Engineering

COMMENTS

  • By Jason Langkamer-Smith - 6:09 PM on February 29, 2012  

    How would you apply a paragraph format? I found FCodes.KBD_PGFWIN, which bring up the paragraph catalog. But then what? Thanks!

  • By Kevin MacDowell - 5:17 PM on October 24, 2012  

    I am getting an “FCodes is undefined” error when trying to run the example above.

  • By max_drawdown - 9:31 PM on January 21, 2013  

    “There is an existing issue with Fcodes not working properly over the Book (Bug# 3099221)”

    How about now?

  • Categories

  • Archives

  • Authors

  • Useful Links

  • Recent Comments

    • Dieter Gust: Very nice several goodies in addition to bugfixes!! I like that very much! Dieter
    • Don Bridges: I expect privacy concerns will tamper IoT for our homes and consumers, but for business it will usher a...
    • Lois Patterson: I’m always happy to see math support, although I’m not currently using FrameMaker. I have...
    • Olga: I know it’s a really old post but I was unable to find any information online. I need to number the...
    • click: yes. http://wwwimages.adobe.com/www .adobe.com/content/dam/Adobe/e n/volume-licensing/pdfs/avl...