Search code examples
helpndoc

Renumbering topic Context ID values using HelpNDoc API


I have found this tutorial for exporting context help ID values to a data file:

const
  // Define the output file
  OUTPUT_FILE = 'c:\tmp\topics.txt';

var
  // Current topic ID
  aTopicId: string;
  // List of output
  aList: TStringList;

begin
  // Init list
  aList := TStringList.Create;
  aList.Add('Topic Caption | Help ID | Help Context');
  aList.Add('--------------------------------------');
  try
    // Get first topic
    aTopicId := HndTopics.GetTopicFirst();
    // Loop through all topics
    while aTopicId <> '' do
    begin
      // Add the topic to the list
      aList.Add(Format('%s | %s | %d', [
        HndTopics.GetTopicCaption(aTopicId),
        HndTopics.GetTopicHelpId(aTopicId),
        HndTopics.GetTopicHelpContext(aTopicId)
      ]));
      // Get next topic
      aTopicId := HndTopics.GetTopicNext(aTopicId);
    end;
    // Create the file
    aList.SaveToFile(OUTPUT_FILE);
  finally
    aList.Free;
  end;
end.

I have done some re-structuring of my revised help documentation and as a result the context numbers are not sequential:

Contents

Using HelpNDoc I was hoping to write a new API script to renumber them but I can't see a suitable API method.

Is this not possible?


Solution

  • Using HelpNDoc API, you can change the help context number of a topic using the HndTopics.SetTopicHelpContext method call. Using simple logic, it is possible to reset all help context numbers. This is described in the following article: Using HelpNDoc scripting capabilities to automatically reset all help context numbers

    The script showcased in the article is even included in recent HelpNDoc's installation folder:

    Context numbers can become messy as HelpNDoc project evolves. This script will reset each topic's context number so that they are setup incrementally from first topic till last one.

    Here is how to run that script:

    • Save a backup of your project in case your need to go back
    • Load your project
    • From HelpNDoc's "Tools" ribbon tab, click "Script Editor"
    • Click the arrow next to "Load script" to display the list of built-in scripts
    • Click "ResetHelpContextNumbers.hnd.pas"
    • Click "Run script"