Skip to content

Host API

Call the host from a plugin method through the Host property on HydroSymPluginBase / HydroManPluginBase. Use it to read project data or trigger actions.

public override void OnMenuAction(OnMenuActionRequest request)
{
    if (request.MenuItemId != "my-search")
        return;

    var bom = Host.GetBom();
    Host.ExportDrawing(new HostExportDrawingRequest
    {
        Format = "pdf",
        OutputPath = @"C:\Temp\drawing.pdf",
    });
    Host.ShowMessage($"BOM rows: {bom?.Items.Count ?? 0}");
}
public override void OnMenuAction(OnMenuActionRequest request)
{
    if (request.MenuItemId != "my-search")
        return;

    Host.ExportPdf(@"C:\Temp\drawing.pdf");
    Host.ShowMessage("Done");
}

Rules

  • Call Host.* only from inside a plugin method, on the thread the host called you on. Every plugin call runs on the host's UI thread, and the host handlers touch VCL windows directly without any locking. Calls from a background thread or after the plugin method has returned are unsafe.
  • Calls are synchronous and block the UI. Plugin methods have no async/await. Keep work short, or show your own progress UI.
  • Host.* works from GetInfo through Finalize. The callback is registered before GetInfo. No document is open during Initialize, so project-scoped calls fail with NO_PROJECT_OPEN there.
  • Errors throw HostApiException with the host's error code. See Error Handling.

Method overview

Full field lists and JSON: HydroSym Host API · HydroMan Host API.

Area HydroSym HydroMan
Project info GetCurrentProject, GetProjectVariables Same
Schematic data GetComponentList, GetIBorders, GetBom —
Drawing PDF ExportDrawing (format must be "pdf") ExportPdf (production layouts only)
BOM PDF ExportBom (format must be "pdf") —
Open, new, save OpenProject, NewProject, SaveProjectAs, SaveFile Same, for .mnf
Variables SetProjectVariables (attribute list, "Project Properties") SetProjectVariables (UserVarList, "Project Variables")
UI ShowMessage, SetStatusBar Same

Notes that apply to both hosts:

  • Methods with an optional projectPath target the active document when you omit it. HydroSym resolves the active window only if it is a schematic.
  • OpenProject blocks until the file is loaded, and your own BeforeFileOpen runs before it returns. readOnly: true opens without a write lock; Host.SaveFile and Host.SaveProjectAs then raise READ_ONLY. If the file is already open, the existing document is returned without focusing it.
  • SetProjectVariables adds or replaces the given keys, marks the document modified when a value changed, and does not save.
  • SaveFile on a never-saved document shows the native Save As dialog. SaveProjectAs and NewProject never show a dialog and refuse to overwrite (FILE_EXISTS).
  • ShowMessage is a modal message box with an OK button. SetStatusBar.duration is ignored; the text stays until replaced.
  • GetCurrentProject.projectId is always empty in API v1. Map projectPath to your own project identifier.

Host.SaveFile saves the open document. It is unrelated to the plugin-side SaveFile method in the HydroSym schema, which HydroSym never calls in API v1. To upload to a vault, call Host.SaveFile or Host.ExportDrawing from OnMenuAction and upload the resulting file yourself.

When to use Host API vs plugin methods

Situation Use
Host needs data from your system Plugin method (host calls you)
Your plugin needs data from the host Host API
Your plugin needs to trigger an export or save Host API
Your plugin needs to show a message Host API (ShowMessage, SetStatusBar)
User clicks your menu item Plugin method (OnMenuAction)

Common pattern: host calls OnMenuAction, your plugin calls Host.*, then returns. Sequence diagram: Upload BOM via menu.