Selection Event


#1

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


(Menno Deij - van Rijswijk) #2

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

(Menno Deij - van Rijswijk) #3

Also, here you find lots of example code

and here you find all SDK documentation
http://www.rhino3d.com/5/rhinocommon/


#4

Thanks a lot
that was exactely what I was looking for

cheers
gerry


(Menno Deij - van Rijswijk) #5

Ok, glad I could help :smile:


(Karol Wierzbicki) #6

I’m using this nice example, but event is not triggered when deselecting objects. Have any one met this problem?


(Menno Deij - van Rijswijk) #7

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


(Karol Wierzbicki) #8

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;

(Menno Deij - van Rijswijk) #9

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


(Karol Wierzbicki) #10

Of course, it really does work like this. Menno Thanks :slight_smile: