Run code when object selected?

I’m trying to figure out how to run some code when an object is selected. I came across this old topic which I think just about answers it for me but need a bit of help. If I understand correctly, I’ll put the OnSelectObjects sub in my plugin class. But where to I put the following line?

RhinoDoc.SelectObjects = (RhinoDoc.SelectObjects + OnSelectObjects)

Thank you,
Sam

For example in PlugIn.OnLoad, or in a command.

I tried placing it in my OnLoad function as well as in a function in a command. I get an error saying it’s an event and can’t be called directly.

Protected Overrides Function OnLoad(ByRef errorMessage As String) As Rhino.PlugIns.LoadReturnCode RhinoDoc.SelectObjects = (RhinoDoc.SelectObjects + OnSelectObjects()) End Function

Am I maybe not getting the right conversion from your c# to VB.net? Here was your c#:
RhinoDoc.SelectObjects += OnSelectObjects;
And here is the VB I’m trying:
RhinoDoc.SelectObjects = (RhinoDoc.SelectObjects + OnSelectObjects())

And I’m not quite sure what you mean by putting in a Plugin.OnLoad. Perhaps you could do a quick VB.net example for me please?

Thank you,
Sam

I’m not familiar with VB.NET event subscription, a quick google seems to indicate that you need to use AddHandler.

Got it, just added following line to OnLoad function:

AddHandler RhinoDoc.SelectObjects, AddressOf OnSelectObjects

Thanks for your help,
Sam

1 Like