Skip to content

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

  1. Add a menu item such as "Open from vault" and handle it in OnMenuAction.
  2. Resolve the local path: download the file or use a cached copy.
  3. Call Host.OpenProject(path). Pass readOnly: true when the user has no lock; the host then opens without a write lock, and Host.SaveFile and Host.SaveProjectAs raise READ_ONLY.
  4. Host.OpenProject blocks until the file is loaded. If you advertised beforeFileOpen, your BeforeFileOpen runs before OpenProject returns. Do not prompt the user there for files you opened yourself; check projectPath and return AllowOpen = true.
  5. If the file is already open, OpenProject returns 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

  1. BeforeFileClose (if advertised) runs before the native "Save changes?" prompt. IsModified tells you whether there are unsaved changes. Return AllowClose = false to veto. Do not release locks here: the user can still cancel the save prompt.
  2. After the close is confirmed, SetProjectVariables (if advertised) runs with the final projectPath. 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.