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}");
}
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 fromGetInfothroughFinalize. The callback is registered beforeGetInfo. No document is open duringInitialize, so project-scoped calls fail withNO_PROJECT_OPENthere.- Errors throw
HostApiExceptionwith 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
projectPathtarget the active document when you omit it. HydroSym resolves the active window only if it is a schematic. OpenProjectblocks until the file is loaded, and your ownBeforeFileOpenruns before it returns.readOnly: trueopens without a write lock;Host.SaveFileandHost.SaveProjectAsthen raiseREAD_ONLY. If the file is already open, the existing document is returned without focusing it.SetProjectVariablesadds or replaces the given keys, marks the document modified when a value changed, and does not save.SaveFileon a never-saved document shows the native Save As dialog.SaveProjectAsandNewProjectnever show a dialog and refuse to overwrite (FILE_EXISTS).ShowMessageis a modal message box with an OK button.SetStatusBar.durationis ignored; the text stays until replaced.GetCurrentProject.projectIdis always empty in API v1. MapprojectPathto 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.