PluginServer

public static class PluginServer
Central repository for all loaded plugins.

Properties

CorePlugins

#
public static IEnumerable<string> CorePlugins { get; }
Gets an enumerator for all the core component library assemblies. This property iterates over all RHP files inside the plugin components folder, whether or not they were put there by the Grasshopper installer.

CustomPlugins

#
public static IEnumerable<string> CustomPlugins { get; }
Enumerate all custom plugin files.

IsLoading

#
public static bool IsLoading { get; }
Gets whether a plugin is currently in the process of being loaded.

The load lock is held for the entire duration of a plugin load, so a lock which cannot be taken right now means another thread is busy loading. Taking the lock the usual way would block until that load completes, so this probes the lock instead of waiting on it. On the loading thread itself the lock is re-entrant and the loading set is consulted directly.

LoadState

#
public static LoadState LoadState { get; }
Gets how far the startup sequence has progressed. Plugins loaded after the startup sequence do not affect this, see PluginLoaded for those.

State

#
public static Plugins State { get; }
Gets the current state of the plugin server. The state is immutable and should never be cached, but always retrieved anew.

YakPlugins

#
public static IEnumerable<string> YakPlugins { get; }
Enumerate all 3rd party plugin files.

Methods

ComponentAssemblies

#
public static IEnumerable<string> ComponentAssemblies(PluginKind kind)
Enumerate over all plugins that Grasshopper would load if it were asked now to do so. This list is not necessarily consistent with the number of plugins that Grasshopper loaded when it started.
kind (PluginKind)Assembly kinds to include in the enumeration.

DescribeUninstall

#
public static string DescribeUninstall(string location)
Describe what uninstalling a plugin would actually do, for putting to the user before it happens.

The two kinds of installation carry very different risk. A custom plugin is no more than an entry on a list of files to load, so removing it changes nothing on disk and can be undone by picking the same file again. A Yak package is files, every version of them, and getting them back means downloading them again — assuming the server still has them.

location (string)Plugin file which would be uninstalled.
A question to put to the user, or null when there is nothing this method knows how to uninstall.

FindPluginForObject

#
public static Plugin FindPluginForObject(IDocumentObject obj)
Find which plugin provides the given document object. It is possible that an object is not associated with any plugin.
obj (IDocumentObject)

FindPluginForObject

#
public static Plugin FindPluginForObject(Type objectType)
Find which plugin provides the given document object. It is possible that an object is not associated with any plugin.
objectType (Type)

ForgetPlugin

#
public static bool ForgetPlugin(string location)
Forget a scoped potential plugin.
location (string)Location to forget.
True if the state of the PluginServer was updated.

InstallCustomPlugin

#
public static FailureKind InstallCustomPlugin(string path)
Add a custom component assembly. This is typically used only for those plugins which are not installed through regular channels, such as plugins being locally developed or debugged.
path (string)

LoadAllScopedPlugins

#
public static (int loaded, int failed) LoadAllScopedPlugins()
Try and load all scoped plugins.
A tuple with loaded and failed counts.

LoadPlugin

#
public static bool LoadPlugin(string location, Assembly assembly, out FailureInfo failure)
Load a plugin assembly into the framework.
location (string)The location of this assembly. If no file location is associated (for example in the case of assemblies compiled in memory) then the assembly FullName may be used instead.
assembly (Assembly)Assembly to load.
failure (out FailureInfo)Message in case of load failure.
True if plugin was loaded successfully.

LoadPlugin

#
public static bool LoadPlugin(string location, out FailureInfo failure)
Attempt to load a plugin from a file.
location (string)Uri of plugin.
failure (out FailureInfo)Message in case of load failure.
True if plugin was loaded successfully.

RemovePlugin

#
public static bool RemovePlugin(string location)
Remove a failed plugin from the list.
location (string)Location to remove from failed list.

ScopeCustomPlugins

#
public static int ScopeCustomPlugins()
Add all custom selected plugin files to the scoped list.
Number of plugins scoped.

ScopePlugin

#
public static bool ScopePlugin(string location)
Scope a potential plugin. This always happens before a plugin is actually loaded.
location (string)Location to scope.
True if the state of the PluginServer was updated.

ScopeStandardPlugins

#
public static int ScopeStandardPlugins()
Add all standard plugins to the scoped list.
Number of plugins scoped.

ScopeYakPlugins

#
public static int ScopeYakPlugins()
Add all yak package installed plugins to the scoped list.
Number of plugins scoped.

UninstallCustomPlugin

#
public static bool UninstallCustomPlugin(string path)
Remove a custom component assembly. This is typically used only for those plugins which are not installed through regular channels, such as plugins being locally developed or debugged.
path (string)

UninstallPlugin

#
public static bool UninstallPlugin(string location, out string report)
Uninstall a plugin, whichever way it was installed.

A custom plugin is only ever an entry on a list of files to load, so removing the entry is the whole job. A Yak plugin is a package on disk, and getting rid of it means deleting that — which Windows will not do while the assembly is loaded, so whatever will not go now is put on FleetingPlugins' removal ledger and dealt with at the next startup.

location (string)Plugin file to uninstall.
report (out string)A sentence for the user describing what happened.
True if the plugin was uninstalled, whether or not the files have gone yet. False if there was nothing this method knows how to remove.

Events

LoadStateChanged

#
public static event EventHandler LoadStateChanged
Raised once for each stage of the startup sequence, when it is reached. A late subscriber should check LoadState first; both the check and the subscription are safe on the UI thread, which is where the stages are reached.

PluginFailed

#
public static event EventHandler<PluginEventArgs> PluginFailed
Raised when a plugin fails to load.

PluginForgotten

#
public static event EventHandler<PluginEventArgs> PluginForgotten
Raised when a scoped plugin is forgotten during the runtime of Grasshopper.

PluginLoaded

#
public static event EventHandler<PluginEventArgs> PluginLoaded
Raised when a plugin successfully loads.

PluginLoading

#
public static event EventHandler<PluginEventArgs> PluginLoading
Raised just before a plugin starts getting loaded.

PluginRemoved

#
public static event EventHandler<PluginEventArgs> PluginRemoved
Raised when a loaded or failed plugin is removed during the runtime of Grasshopper.

PluginScoped

#
public static event EventHandler<PluginEventArgs> PluginScoped
Raised when a new plugin is discovered during the runtime of Grasshopper.