The plugin derived class

Working in c#. I would like to check the user license from within the plugin derived class - if they don’t have a license I want to unload the plugin/prevent them from using the commands.

What’s the best way to do this? License check is fine - it’s the “preventing them from using the plugin” that I’m trying to work out the best solution for.

You could load the plugin at startup, and override the OnLoad method. You can choose to return an error in that method if you do not want the plugin to load or return success if all goes to plan.

You don’t even need to force loading at start up. The return code from OnLoad will be respected. If you return ErrorShowDialog or ErrorNoDialog, then your plug-in will not be executed.

To elaborate on what Luis and Steve mentioned, you can do something like this:

/// <summary>
/// Is called when the plug-in is being loaded.
/// </summary>
/// If a load error is returned and this string is set. This string is the 
/// error message that will be reported back to the user.
/// <returns>An appropriate load return code.</returns>
protected override LoadReturnCode OnLoad(ref string errorMessage)
  if (!HaveValidLicense())
    errorMessage = string.Format("Unable to load {0} plug-in. No valid license found.", this.Name);
    return LoadReturnCode.ErrorShowDialog;
  return LoadReturnCode.Success;

Or, you could popup your own UI, giving the customer directions on how to purchase a license, and just return LoadReturnCode.ErrorNoDialog.

Thanks very much all 3 of you! Very useful - am putting it into practice right now.


In Rhino 5, we have the render plugin class:

public class Plugin : Rhino.PlugIns.RenderPlugIn,…

and when loading the plugin, if some predefined MDL folder does not exist, user can chose to avoid loading the plugin.
We then return ErrorShowDialog code:

protected override Rhino.PlugIns.LoadReturnCode OnLoad(ref string errorMessage)


Now, the plugin is not loaded but the Iray renderer is still listed in the list of viewport renderers.

When user chose Iray, the viewport freezes, when user chose wireframe, Rhino crashes.
Is there something to do in addition to returning ErrorShowDialog ?
To unregister the viewport renderer?

I’ll take a look at this.


1 Like

@nvp, I have created a pull request that should fix this problem. As part of the non-loading all custom render content and other extensions registered by the plug-in are also unloaded.

With the next WIP please test this and report whether it works or not. (It does in my own tests :wink: )


Hi @nathanletwory, this is an issue we would like to address in Rhino 5. Would it be possible to port the fix?

I’m not sure about that. I’ll have to ask @andy. I haven’t really ever touched the Rhino 5 code base.


@nvp, for Rhino 5 there will be no more changes. Note that the realtime integration code does not work in v5.

Is there nothing which can be done on our side then?

As I understand it the plug-in developer should take care themselves to clean up in case of load failure. Maybe @stevebaer or @andy can tell more.

RH-38119 is fixed in the latest WIP

@nvp, could you confirm this works now as expected in Rhino WIP for your plug-in? Thanks.