Selection Event

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");
        }
    }
}
1 Like

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 :smile:

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?:slight_smile:

        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 :slight_smile: