SampleCSWinForms RhinoCommon


I have some short questions that refer to the SampleCSWinForms:

  1. In the example I noticed that the SampleCsObjectPropertesPage is not there by default (OnLoad) However, once I execute any of the the SampleCs…commands, then when I select an object the Sample Object Property Page is there. Why is that? (The same with Document Properties and Options…they only appear after executing any of the commands)

  2. I guess the best way (or only way) to connect the SampleCsObjectPropertiesPage with the selected Object or Objects is over the UserControl instance and ShouldDisplay :

public override object PageControl => m_control ?? (m_control = new SampleCsObjectPropertiesUserControl());

But once I select an object and I try to acces “m_control” in ShouldDisplay, I get the message that m_control is null. This happens only before I actually click on the new ObjectProperty icon for the first time…which means that this Instance is initialized only after I click on it… After that it works fine…even when some other Property Page is selected, the m_control is there… Why is that? Can this Property Page be initialized OnLoad?


Hello Milos,

In answer to your questions:

  1. The sample plug-in is a Load On Demand plug-in and will not get loaded until a command inside the plug-in is run. Dragging and dropping the plug-in onto Rhino will load the plug-in but the properties system will not add the page until the selection changes or some other command is run, something needs to tell the properties system it needs to update.
  2. ShouldDisplay gets called anytime the current selection set changes or at the end of a command running. ObjectPropertiesPage.ShouldDisplay tells the property system if it is capable of operating on the current selection set, it should be a simple function that evaluates what is selected and return as soon as possible. The ObjectPropertiesPageEventArgs passed to this function includes a IncludesObjectsType method to quickly check for specific object types. The ObjectPropertiesPage.UpdatePage method gets called when the page becomes active and is where control initialization should happen.

If you need access to the current selection when a control state changes you should use the following:

      var args = new ObjectPropertiesPageEventArgs(this);

The PageControl property is only called when the page is becoming the active and the property system needs to display and resize it. The properties system does not care when the control instance is created so there is nothing stopping your page constructor from creating an instance of the control when the page instance is created if you wish. You could also do something like this if you want:

In summary the following is the work flow:

  • The plug-in is loaded
  • PlugIn.OnLoad method is called while loading
  • PlugIn.OptionsDialogPages method is called while loading
  • ObjectPropertiesPage.ShouldDisplay is called anytime the selection changes or when command execution is completed.
  • ObjectPropertiesPage.UpdatePage is called when a page becomes the active properties page.