Hi everyone!
I’m working on an in-house developed plug-in for Rhino 5, using C#.
We’d like to disable certain commands from our own plug-in, either because they’re not meant for the end user to use or because they don’t ship with our own license.
I’m aware you can hide any command by decorating the Command’s child class with [CommandStyle(Style.Hidden)] (which prevents the autocomplete to show the command’s name), but that doesn’t prevent it to be executed anyway, knowing its name.
I still want the plugin to load and work, so to say, but without said (specific) command.
Any advice?
To sort of expand on that I’d like to add that when I overload my plugin class:
//called at startup
protected override LoadReturnCode OnLoad(ref string errorMessage)
{
if (License.IsValid && License.HasFlag(premiumUser))
{
RegisterCommand(new Commands.someCommand());
}
}
I was expecting to have someCommand loaded ONLY if mentioned in the onLoad function (as showed above). This is not the case, in fact, I have all the commands in my current project, I don’t mean “phisically” I mean, they are compiled, therefore somewhere in the rhp package, I actually mean, I wasn’t expecting them to be available in my Rhino instance.
When your plug-in is first loaded, Rhino uses reflection to look for all public classes that derive from Command through reflection and attempts to make an instance of each. If you don’t want your commands to automatically be created, make them private (get rid of the word public in the Command declaration.)
There is a virtual function on the plug-in class called CreateCommands. This is where the above logic I mention is performed. You can override this function and do the following:
Create an instance of each command you want available in Rhino.
Call RegisterCommand for each of these command instances
Thanks @dale, @stevebaer, my commands are now registering as intended. I’ve used the overriding CreateCommands() approach .
Just a small advice, if I may. You guys might wanna consider adding one or two lines in the API documentation. I can see that there is something in CreateCommands() (in http://developer.rhino3d.com/api/RhinoCommon/html/T_Rhino_PlugIns_PlugIn.htm), but @stevebaer’s input here has been useful nonetheless, other people might like to have it on the docs too ;).