Table of Contents

CadPluginManager

from OpenCAD2D.Plugins import CadPluginManager

class CadPluginManager(System.Object) ยท CadPluginManager in the .NET reference

The command plugins of the presenter, as AutoCAD's NETLOAD and APPLOAD keep them (A14 of the plan): loaded from a .dll, the folder of one, or the plugin folder, unloaded and loaded again while the presenter runs, their commands added to the command line of every drawing open (CadPluginManager.Attach), every load written in the load log (CadPluginManager.Log) and logged with its full path.

Constructors

__init__

.NET

def __init__(
    self,
    loader: CadPluginLoader,
    pluginFolder: str,
    settingsPath: str,
    shadowFolder: str | None = ...,
) -> None

Makes the manager of the presenter's plugins, reading its startup list and trusted folders from settingsPath.

Properties and fields

LoadCommand

.NET

LoadCommand: ClassVar[str]

The name of the command that loads a plugin by its path: PLUGINLOAD, alias NETLOAD.

ReloadCommand

.NET

ReloadCommand: ClassVar[str]

The name of the command that loads a plugin again from its file by its name: PLUGINRELOAD.

UnloadCommand

.NET

UnloadCommand: ClassVar[str]

The name of the command that unloads a plugin by its name: PLUGINUNLOAD.

CanUnload

.NET

@property
def CanUnload(self) -> bool

Gets whether unloading a plugin frees its code (.NET 8), or only switches it off (.NET Framework).

ConfirmUntrusted

.NET

@property
def ConfirmUntrusted(self) -> System.Func[str, bool] | None
@ConfirmUntrusted.setter
def ConfirmUntrusted(self, value: System.Func[str, bool] | None) -> None

Gets or sets what is asked before a plugin outside the trusted folders is loaded: given the file's full path, it says whether to load it, as a dialog that asks the user does. Null, as it is until set, loads none.

Log

.NET

@property
def Log(self) -> System.Collections.Generic.IReadOnlyList[CadPluginLogEntry]

Gets the load log, the oldest line first; CadPluginManager.LogChanged is raised as it grows.

PluginFolder

.NET

@property
def PluginFolder(self) -> str

Gets the plugin folder, always trusted, whose plugins are loaded at every start.

Plugins

.NET

@property
def Plugins(self) -> System.Collections.Generic.IReadOnlyList[CadLoadedPlugin]

Gets the plugins known in this session, loaded or not, in ordinal order of their names, either case the same, then of their paths.

SettingsPath

.NET

@property
def SettingsPath(self) -> str

Gets the JSON file of the startup list and the trusted folders.

ShadowFolder

.NET

@property
def ShadowFolder(self) -> str

Gets the folder the plugins' files are copied to and loaded from.

StartupList

.NET

@property
def StartupList(self) -> System.Collections.Generic.IReadOnlyList[str]

Gets the paths of the startup list, loaded at every start after the plugin folder, in the order they were put on it.

TrustedFolders

.NET

@property
def TrustedFolders(self) -> System.Collections.Generic.IReadOnlyList[str]

Gets the trusted folders, full paths: the plugin folder first, then those added, in the order they were added.

Events

LogChanged

.NET

@property
def LogChanged(self) -> System.EventHandler[System.EventArgs]
@LogChanged.setter
def LogChanged(self, value: System.EventHandler[System.EventArgs]) -> None

Raised when a line is added to CadPluginManager.Log.

PluginsChanged

.NET

@property
def PluginsChanged(self) -> System.EventHandler[System.EventArgs]
@PluginsChanged.setter
def PluginsChanged(self, value: System.EventHandler[System.EventArgs]) -> None

Raised when a plugin is loaded or unloaded, or put on or off the startup list.

Methods

AddTrustedFolder

.NET

def AddTrustedFolder(self, folder: str) -> bool

Adds a trusted folder, whose plugins load without asking, and writes the list.

Attach

.NET

def Attach(self, registry: CadCommandRegistry) -> System.Collections.Generic.IReadOnlyList[str]

Adds the commands of the loaded plugins to a registry, and those of every plugin loaded later, with PLUGINLOAD (alias NETLOAD), PLUGINUNLOAD and PLUGINRELOAD, which ask on the command line for a path or a name. A command the registry has already is left, so that the window's own PLUGINLOAD, which shows a file dialog, can be added first.

Detach

.NET

def Detach(self, registry: CadCommandRegistry) -> bool

Takes the plugins' commands and those CadPluginManager.Attach added out of a registry, as when its drawing is closed.

Dispose

.NET

def Dispose(self) -> None

Unloads every plugin and deletes the copies of their files that can be deleted; a copy the runtime still holds is deleted at a later start.

Find

.NET

def Find(self, name: str) -> CadLoadedPlugin

Finds a plugin known in this session by its name, either case the same.

IsTrusted

.NET

def IsTrusted(self, path: str) -> bool

Gets whether a file or folder lies in one of the trusted folders.

Load

.NET

def Load(self, path: str) -> CadPluginResult

Loads a plugin for this session, as PLUGINLOAD and NETLOAD do: from a .dll (with the plugin.json beside it, where there is one), or the folder of a plugin. Its commands are added to every registry attached. Refused, with the reason, where the path is outside the trusted folders and not confirmed, the plugin needs a newer API, a plugin of its name or path is loaded already, or it has no command.

LoadAtStart

.NET

def LoadAtStart(self) -> System.Collections.Generic.IReadOnlyList[CadPluginResult]

Loads what is loaded at every start: each .dll directly in the plugin folder, in ordinal order of the names (either case the same), then each folder below it that has a plugin.json or a .dll directly in it as one plugin, at any depth, in the order of the walk (CadSupportWalk), then the startup list in its order. A folder with neither is walked into, and one with either is not. The plugin folder is trusted, so nothing is asked. A plugin loaded already is left; each other is a line of the log, and a .dll that is no plugin, or cannot be loaded, is refused with its line and does not stop the others.

Reload

.NET

def Reload(self, name: str) -> CadPluginResult

Loads a plugin again from its file, as PLUGINRELOAD does, unloading it first where it is loaded: a plugin's author changes its code, builds it and reloads it with the presenter running. On .NET Framework the build loaded first in the session stays, and the result says so.

Remove

.NET

def Remove(self, name: str) -> bool

Forgets a plugin: it is unloaded where it is loaded, taken out of CadPluginManager.Plugins and off the startup list, and the list is written. Loading its file again makes it known anew. A plugin of the plugin folder cannot be forgotten, because it is loaded at every start.

RemoveTrustedFolder

.NET

def RemoveTrustedFolder(self, folder: str) -> bool

Takes a trusted folder off the list and writes it; the plugin folder stays trusted.

SetLoadAtStartup

.NET

def SetLoadAtStartup(self, name: str, loadAtStartup: bool) -> bool

Puts a plugin on the startup list, or takes it off, and writes the list; a plugin of the plugin folder is loaded at every start anyway.

Unload

.NET

def Unload(self, name: str) -> CadPluginResult

Unloads a plugin, as PLUGINUNLOAD does: its commands go from every registry, and a run of one going on fails at its next step. On .NET 8 its load context is freed; on .NET Framework its code stays loaded, switched off, until the presenter restarts. It stays in CadPluginManager.Plugins, so that it can be loaded again.

Operators and Python protocols

__enter__

def __enter__(self) -> Self

__exit__

def __exit__(self, *args: object) -> None