Scripting for TCS Unleashed

Monday, June 15 2009 @ 7:58 PM, By Mayank Agrawal

[Enhanced Anchored Frame Conversion in FM Linking]

Scripting in TCS

The feature of Scripting in RoboHelp can be leveraged in TCS to extend
the feature of conversion of FrameMaker documents to RoboHelp XHTML topics
(FrameMaker Linking). TCS users need certain tweaks in FM Linking and
Import feature to suit the feature as per their requirements. Some of
these tweaks can be achieved through Scripting. This blog talks about
one such tweak and explains how one can write a script to achieve this.

Enhanced Anchored Frame Conversion
through Scripting

During update of a linked FrameMaker document in RoboHelp, an anchored
frame present in the document is converted to a web supported image in
RoboHelp XHTML topic. The properties of anchored frames are also converted
to image settings (image size, image border etc.) in XHMLT topics. However,
at times, a user may need to tweak these settings for individual images.
Or a user may not be satisfied with the quality of image generated in
RoboHelp and may wish to replace it with a processed image.

We can achieve all of this through a simple script. Here is how we can
write and use such a script maintaining the Single Sourcing route.

We can observe that the problem involves two steps.

1. Mention the image settings for each anchored

We can achieve this by inserting a marker in the FrameMaker document
before each anchored frame to which settings are to be applied. Let us
define a new marker type say “Graphic” for this purpose.

Insert this marker before the anchored frame. Consider two image settings
as of now viz. image replacement and image resizing.



resize=150 means zoom in the image size to 150% while inserting in XHTML

replace=true means  whenever this marker is found in the document,
replace the image with a new image of the same name placed in a specified
images folder.

(Non-programmers may skip this section further and jump to the next section to start using the script)

2. Process and apply those settings to the
corresponding image

 Run a script to process the marker to understand the individual
image settings mentioned above and modify the image tag in XHTML topic
in RoboHelp accordingly.

This script shall be executed once the RoboHelp topic has been generated
from RoboHelp User Interface.  This script shall patch the image
tags of the topic with the help of following steps.

a.  Start reading the HTML of the topic in the form of a token
list. Here is an example of an HTML token list  <html> <head>
<title> </title> </head>  etc.

b. Look for marker (basically XHTML PI) in the topic. The marker in
HTML looks like this <?rh_marker name="Graphic" text="resize=150,replace=true"?>

c. Obtain the maker name and text and check if its name matches with
our “Graphic” marker.

var tknmgr = RoboHelp.getTokenManager(filepath);
if (tknmgr != null)
var bResize = false;
var bReplace = false;
var token = tknmgr.item(index);
var strName =;

//Looking for marker PI
if ((token.tokenType == tokenPI_Identifier) && (strName.indexOf(markerToken) != -1))
// Extract the string with attribute name
strMarkerName = strName.substring(strName.indexOf("name=")+6, strName.indexOf("text")-2);
// extract the string with attribute text
strMarkerText = strName.substring(strName.indexOf("text=")+6, strName.indexOf("?>")-1);
// if the marker is of type graphicsStyle
if (strMarkerName = graphicMarker)
//Process marker

d. Find marker attributes “resize” and “replace”

var strResizePercent = FindMarkerTextAttributeValue(strMarkerText, "resize");
// see if the processing instructions contains resize
if (strResizePercent  != "")
nResizePercent = parseFloat(strResizePercent);
bResize = true;
var strReplace = FindMarkerTextAttributeValue(strMarkerText, "replace");
// see if the processing instructions contains replace
if(strReplace == "true")
bReplace = true;

e. Look for image <img> tag. When found, do resizing and image
replacement stuff.

For resizing, read the current width and height and calculate the new
width and height as per the percentage mentioned in the marker text. For
replacing the image, update the “src” attribute of the img tag with the
new image path. New image path can be obtained by the image folder path
mentioned in the script and the current image name.

if(token.tokenType == RoboHelp.TokenType.TOKENTAG && token.tagType == RoboHelp.TagType.TAGIMAGE)
// Do resizing and replacing stuff

f. Save the topic.

g. Repeat this for all the topics in the project.

The Complete Functional Script

Please download the attached script file for the entire functional script. The
script has the following variables which should be updated by the user
before using the script.

var imagePath = "/Images";  //Image folder path relative to the project folder
var graphicMarker = "Graphic";  //FM marker type

Further Enhancements to the script

  • This script can be further enhanced to include other image settings
    like image margin, image border etc. for each image.
  • The script can be changed to not to replace the RoboHelp generated
    images and do some post processing of generated images using Adobe

Several other TCS functionalities may be designed using scripting.
Explore the power of scripting and extend TCS features.

Happy Scripting !!!

Mayank Agrawal
RoboHelp Engineering


  • By M. Hunsberger - 8:28 PM on December 14, 2012  

    hmmmm… I’m using RH 10 with FM 11. I tried the exact scenario mentioned, but the markers don’t appear to be showing up in the HTML. Did this change for RH 10?

  • By M. Hunsberger - 8:52 PM on December 14, 2012  

    Okay, I partially figured out what I was doing wrong. I was putting the marker inside the anchored frame.

    This is my code now:


    However, the script is not replacing the image with the one I put in the /Images folder. Any ideas?

  • Categories

  • Archives

  • Authors

  • Useful Links

  • Recent Comments

    • Bjørn Smalbro: Hi Welcome aboard to the new folks! I do have a couple of questions; 1: I have every sent in my...
    • Dieter Gust: Kapil How can I check the DITA-OT version which is installed with FrameMaker?
    • Dieter Gust: >In this update, we have made a good number of enhancements as well as addressed many issues.”...
    • Mark Carson: Whoops, I meant “on” it…
    • Mark Carson: Sure hope Praveen likes to work on a Mac and wishes FrameMaker was no it.