Accessing Plugin from Command

rhinocommon

(Tom D.) #1

Hi all,

Quick plugin architecture question:

I have a plugin that loads some resources when it first initializes, the idea being that I want the plugin to stay active throughout the session to capture document events.

My plugin also has some commands. When a command runs I would like to access the resources in the plugin - specifically some of the properties and methods, but I’m not sure the best way to do this… Any pointers?

Thanks!

Tom


(Andrew le Bihan) #2

C# or C++?


(Tom D.) #3

Using C# - thanks Andrew!


(Steve Baer) #4

You can call the PlugIn property on your command and cast it to the actual plugin type defined in your project.

http://developer.rhino3d.com/api/RhinoCommon/html/P_Rhino_Commands_Command_PlugIn.htm


(Tom D.) #5

Thank you Steve. That works like a charm with one lingering doubt:

I’m relatively new to C#, but finding it quite fun, fast and powerful.

One thing that is confusing me, however, is understanding when I am getting an actual object (in this case a Plugin), or a reference to an object.

Am I correct that I am getting a reference to the plugin that owns the command, and not a new Plugin object? There is nothing in the documentation that tells me this, so perhaps this is a C# assumption I should be aware of?


(Steve Baer) #6

You are not getting a new instance for every call to this property. Only one instance of you plug-in derived class is ever created.


(Tom D.) #7

Perfect. Thanks!!