HelpNDoc is so easy to use that a complete multi-format and multi-device documentation can be produced in just a few minutes after downloading and trying HelpNDoc for the first time thanks to its intuitive user interface and Microsoft Word-like topic editor. It is also extremely powerful and provides many advanced tools to simplify and speed-up the creation of amazing help files and manuals. One of those advanced feature is the script editor which lets you manipulate HelpNDoc through a scripting language. Let’s see how the script editor can help you create the most useful help files in the shortest amount of time possible.

Scripting your documentation projects

HelpNDoc’s script engine provides access to manage every HelpNDoc’s features: table of contents, topic editor, keywords, library items… the possibilities are endless.

HelpNDoc’s script engine is based on the Pascal programming language which is very easy to understand and type. It provides access to a wide range of methods to control your documentation projects.
To use HelpNDoc’s scripting capabilities, you’ll need to enter a script or load one in the script editor. The script editor provides an editor with syntax highlighting as well as script building and running capabilities. It can be accessed using the “Script Editor” button in the “Tools” ribbon tab.

HelpNDoc's script editor

Use scripts to manage the table of contents

The table of contents is the main entry point to most of your help, manuals and documentation content. HelpNDoc’s script engine can help you automate the creation of a complex table of contents in a fraction of a second.

Let’s say that you have a text file containing a list of topic names that you’d like to quickly integrate in HelpNDoc. This is the perfect job for HelpNDoc’s scripting engine: we’ll load that file, and for each line, we’ll create a new topic and set its caption. Let’s see how this can be done using HelpNDoc’s script editor:

var
  // List of lines in the file
  oList: TStringList;
var
  // Current line number
  nLine: Integer;
var
  // ID for the newly created topic
  sTopicId: string;

begin
  // Create objects
  oList := TStringList.Create();
  try
    // Load the lines from a file
    oList.LoadFromFile('c:\tmp\topics.txt');
    // Iterate through each line
    for nLine := 0 to oList.Count - 1 do
    begin
      // Create a new topic
      sTopicId := HndTopics.CreateTopic();
      // Set its caption based on the current line
      HndTopics.SetTopicCaption(sTopicId, oList[nLine]);
    end;
  finally
    // Free objects
    oList.Free;
  end;
end.

Adding some content via scripts

HelpNDoc’s script engine can also be used to manage the content of a topic. Let’s see how easily it is to use that feature.

We have now automated the creation of the table of contents but we could also script the creation of the content for those topics. Let’s expand our previous sample and imagine that each topic’s content is contained in an HTML file named after the topic caption. Our whole script would become something like:

var
  // List of lines in the file
  oList: TStringList;
var
  // Current line number
  nLine: Integer;
var
  // ID for the newly created topic
  sTopicId: string;  
var
  // Editor
  oEditor: TObject;

begin
  // Create objects
  oList := TStringList.Create();
  oEditor := HndEditor.CreateTemporaryEditor();
  try
    // Load the lines from a file
    oList.LoadFromFile('c:\tmp\topics.txt');
    // Iterate through each line
    for nLine := 0 to oList.Count - 1 do
    begin
      // Create a new topic
      sTopicId := HndTopics.CreateTopic();
      // Set its caption based on the current line
      HndTopics.SetTopicCaption(sTopicId, oList[nLine]);  
      // Load the content from another file
      HndEditor.Clear(oEditor);
      HndEditor.InsertFile(oEditor, 'c:\tmp\' + oList[nLine] + '.html');
      // Set the content of the topic
      HndEditor.SetAsTopicContent(oEditor, sTopicId);
    end;
  finally
    // Free objects
    HndEditor.DestroyTemporaryEditor(oEditor);
    oList.Free;
  end;
end.

Endless possibilities thanks to HelpNDoc’s scripting engine

We have explored a very tiny part of what HelpNDoc’s script engine is capable of through this samples. Thanks to this powerful scripting system, you will be able to easily let your computer do what it is meant to do: automate repetitive tasks and simplify your life. As a technical writer, there are plenty of tasks that can be automated and we encourage you to take a look at the huge list of methods available through HelpNDoc’s scripting system to start automating your repetitive tasks and create the most amazing help and documentation projects.

See also...

Find and replace in script editor, single letter words support in HTML search engine, and more in HelpNDoc 7.7

We are glad to announce the release of HelpNDoc 7.7, a major update of the popular help authoring tool which can be downloaded completely free for personal use and evaluation purposes. This major …

Read More →
Create a new HTML template to customize your online documentation projects

The recent release of HelpNDoc 6.4 includes an enhanced single page HTML template with the ability to optionally add a table of contents to the produced single page HTML documentation. We obviously …

Read More →
Bulk edit the status of all topics in your documentation project

HelpNDoc 6.0 added support for topic status, which greatly simplifies the maintenance of documentation projects for technical authors: topics can be tagged as being “Out of Date”, “In Progress”, …

Read More →
Automatically merge multiple topics from your documentation into a single one using a script

A standard help authoring tool such as HelpNDoc is a software where you generally write and organize content in order to produce documentation files for the end-user. As revisions are needed, the …

Read More →

Categories: articles