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.
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.
- Find and replace in script editor, single letter words support in HTML search engine, and more in HelpNDoc 7.7
- Create a new HTML template to customize your online documentation projects
- Bulk edit the status of all topics in your documentation project
- Automatically merge multiple topics from your documentation into a single one using a script
- Quickly sort help content, documentation headings or eBooks topics by title