I would like to catch selection events to show custom data
but not sure how and where to look at
I have seen the selectionhandler in Rhinodoc but not sure how to use it
any hint ?
gerry
I would like to catch selection events to show custom data
but not sure how and where to look at
I have seen the selectionhandler in Rhinodoc but not sure how to use it
any hint ?
gerry
I assume you use RhinoCommon? with C#?
In that case you subscribe to the SelectObjects like so:
RhinoDoc.SelectObjects += OnSelectObjects;
Then you require a method called OnSelectObjects that does something with the selection information like so:
void OnSelectObjects(object sender, RhinoObjectSelectionEventArgs args)
{
if(args.Selected) // objects were selected
{
// do something
foreach(RhinoObject obj in args.RhinoObjects)
{
RhinoApp.Writeline(obj.Id+" was selected");
}
}
else //objects were de-selected
{
// do something
foreach(RhinoObject obj in args.RhinoObjects)
{
RhinoApp.Writeline(obj.Id+" was deselected");
}
}
}
Also, here you find lots of example code
and here you find all SDK documentation
http://www.rhino3d.com/5/rhinocommon/
Thanks a lot
that was exactely what I was looking for
cheers
gerry
Ok, glad I could help
Iām using this nice example, but event is not triggered when deselecting objects. Have any one met this problem?
Ah, I see that in that case you also need to subscribe the same event handler to RhinoDoc.DeselectObjects
http://4.rhino3d.com/5/rhinocommon/html/E_Rhino_RhinoDoc_DeselectObjects.htm
Yes I did it before. Have you tried it with DeselectObjects? Is it only me having this problem?
RhinoDoc.SelectObjects += OnSelectObjects;
RhinoDoc.DeselectObjects += OnSelectObjects;
There is a third event, RhinoDoc.DeselectAllObjects
. If you go from a selection to no selection, this will get fired.
If you have multiple objects selected, and deselect one of them using Ctrl+Click, the OnSelectObjects event handler will be called with args.Selected = false
Of course, it really does work like this. Menno Thanks
Hi Menno,
Thanks for the code, I tried to run it in grasshopper c#, and it works well, while,
the problem I find is I cannot unsubscribe it after running the battery once,
do you have idea? thanks.
Welcome! Can you post the relevant code and explain a bit more what is going wrong where?