You can choose how your library items (pictures, movies, documents…) are handled by HelpNDoc: they can be included within your project, or they can be dynamically included at generation time, when you choose to build your final documentation files. Using the second option, you provide a path for your media items so that HelpNDoc can find and include them when needed. This is very useful to be able to handle those items from outside of HelpNDoc, share them with a third party software…
However, a problem might occur if those items need to be moved on your hard drive or networked path: to make sure HelpNDoc can still find your media elements, you’ll need to manually update all of them one by one. As this can be a very long, tedious and error-prone task, this is great use case for HelpNDoc’s powerful script editor. Let’s see how we can leverage it to quickly update the whole library in a few seconds.

HelpNDoc’s script editor to the rescue

All editions of HelpNDoc include the script editor: you can use it to write instructions from the HelpNDoc API to automate repetitive tasks.

Use the script editor to update the library items

Once you have opened the project you need to update and launched HelpNDoc’s script editor, you can begin typing the script we will use to update the library:

  REPLACE_FROM = 'c:\doc';
  REPLACE_TO   = 'd:\documentation';

var aList: THndLibraryItemsInfoArray;
var nCnt: Integer;
var sFilePath: string;

  // Get all items in the library
  aList := HndLibraryItems.GetItemList([]);
  // Go through each of them
  for nCnt := 0 to Length(aList) - 1 do
    // Get its file location
    sFilePath := HndLibraryItems.GetItemUrlFile(aList[nCnt].id);
    // Do we need to replace this one ?
    if ((sFilePath <> '') and (Pos(UpperCase(REPLACE_FROM), UpperCase(sFilePath)) > 0)) then
      // Yes we do: update the path
      sFilePath := StringReplace(sFilePath, REPLACE_FROM, REPLACE_TO, [rfIgnoreCase]);
      // Save it
      HndLibraryItems.SetItemUrlFile(aList[nCnt].id, sFilePath);

You simply need to change the REPLACE_FROM and REPLACE_TO constants to make sure HelpNDoc finds and replaces the correct values, then hit “Run script” and let HelpNDoc do the hard work for you: in a few seconds, your whole library will be updated to use your new path.

Here is how this script works:

  • It gets a list of all library items in the opened project
  • For each if those items, it checks if it is linked to a file path it needs to update
  • If it is, it updates the path and moves on to the next item

Other ways to leverage HelpNDoc’s API to save time

Almost all aspects of HelpNDoc can be automated using HelpNDoc’s API. We have seen how we can automatically update all library items, but it can also use it to automate help and documentation creation, or export Help IDs and Help Context numbers for your developers and much more…
You can review HelpNDoc’s API documentation to learn more about the capabilities of HelpNDoc’s powerful script editor.

See also...

CHM help file size and position [chm] [featured]
How to Customize the Initial Position and Size of CHM Help Files

Creating CHM (Compiled HTML Help) files with HelpNDoc is a breeze, thanks to its user-friendly interface and powerful features. In this article we’ll look into the specifics of how you can set the …

Read More →
Produce MarkDown with the HelpNDoc Help Authoring Tool [markdown] [featured]
Balancing Security and Usability: Best Documentation Formats for Internal Sharing

Sharing documentation effectively and securely is critical in the modern workplace. Whether you’re distributing internal manuals, project documentation, or company policies, the HelpNDoc help …

Read More →
Dynamic content script generating PDF document [dynamic] [featured]
Introducing Groundbreaking Dynamic Content Capabilities in the HelpNDoc Help Authoring Tool Version 9.1

In the ever-evolving world of documentation and help authoring, the arrival of HelpNDoc 9.1 marks a significant milestone. This latest update isn’t just a routine enhancement; it’s a game-changer, …

Read More →
HelpNDoc's character analyzer illustration [illustration] [Featured]
Tech Writers' Secret Weapon: The Unique Advantages of Using HelpNDoc's Characters Analyzer

HelpNDoc has been a go-to solution for professionals seeking to create high-quality, engaging, and user-friendly documentation. However, it’s not just its user-friendly interface or its versatile …

Read More →

Categories: articles