PDM integration¶
A PDM plugin typically opens files from a vault, tracks which file is open, and checks the file back in when the user closes it. Both hosts support this through Host.OpenProject, the two file hooks, and SetProjectVariables on close.
Open from the vault¶
- Add a menu item such as "Open from vault" and handle it in
OnMenuAction. - Resolve the local path: download the file or use a cached copy.
- Call
Host.OpenProject(path). PassreadOnly: truewhen the user has no lock; the host then opens without a write lock, andHost.SaveFileandHost.SaveProjectAsraiseREAD_ONLY. Host.OpenProjectblocks until the file is loaded. If you advertisedbeforeFileOpen, yourBeforeFileOpenruns beforeOpenProjectreturns. Do not prompt the user there for files you opened yourself; checkprojectPathand returnAllowOpen = true.- If the file is already open,
OpenProjectreturns the existing document without focusing it.
Host.OpenProject uses the same load path as File > Open, so the same hooks fire either way.
Guard files the user opens directly¶
Advertise beforeFileOpen to see every file the user opens through File > Open, drag and drop, the recent list, or the command line. The request contains the path and the current project variables. Return AllowOpen = false to discard the document silently, for example when the file is not checked out to this user. The host shows no message; call Host.ShowMessage first if the user should know why.
RemoveVariables deletes variable keys in memory, for example stale vault metadata. The file on disk is not rewritten and the document is not marked modified.
Close and check in¶
BeforeFileClose(if advertised) runs before the native "Save changes?" prompt.IsModifiedtells you whether there are unsaved changes. ReturnAllowClose = falseto veto. Do not release locks here: the user can still cancel the save prompt.- After the close is confirmed,
SetProjectVariables(if advertised) runs with the finalprojectPath. HydroSym also sends the attribute list; HydroMan sends an empty map. This is the point to upload the file and release the lock.
Both hooks fail open: if your plugin throws, the open or close continues. In HydroSym the hooks fire only for schematics, not for symbol files. In HydroMan they do not fire for a manifold that has never been saved.
Map projectPath to your vault item yourself. GetCurrentProject.projectId and PluginContext.projectId are always empty in API v1.
Capabilities¶
| Capability | HydroSym | HydroMan |
|---|---|---|
beforeFileOpen |
Yes | Yes |
beforeFileClose |
Yes | Yes |
setProjectVariables |
Yes, receives the attribute list on close | Yes, receives an empty variables map on close |
getProjectVariables |
Yes, on open and before CLI PDF export | Not a plugin method |
getFileStatus |
Called on open if advertised; result unused | Not a plugin method |
Use DeriveCapabilities() so the list matches the methods you override. Sequence diagrams: HydroSym ยท HydroMan.