Mouse Events in Grasshopper?

Hi guys,

I am wondering how difficult it would be to interact with Grasshopper geometry with mouse events in the rhino view port? Do the Grasshopper SDK and Rhinocommon support such an ad-on? The type of interaction I am thinking about is more in the lines of object selection, so instead of retrieving an object with a list item, the user would be able to select it with a mouse event.



1 Like

Hey Michael,

thanks for the reply, I checked out Mouse Rat, but its not really what I am after, and the link to the latest release of Selectable Preview is not available. Do you know if either of them has open source code? I haven’t been able to find it, so I guess they might not be open source

There are multiple ways in retreiving the screen coordinates of a mouse. All you need, if you have the screen coordinate is to use the rhinocommon method ScreenToClient and ClientToWorld. It will give you a line, because we are moving in 3d space. So intersecting it with plane or an geometry is what you need to do as well if you like to get a point. Mouse screen coordinates can you get by using user32.dll or the eto.forms framework gives you a platform independent solution (I guess, I just know from WinForms and Wpf -> so I think there must be an equivalent for Eto)

1 Like

@rawitscher-torres The Selectable Preview does exactly what you are needing. I downloaded it fine from the Food4Rhino the version 0.2. Try it again, if you can’t, here is the file:

selectablepreview_0.gha (28.5 KB)

Then, you input the geometry that you want to select. The output will be the index and the path. If you use List Item now, you will retrieve it automatically. Here is an example:

Streets with values for each segment. There is 2394 segments and values. Clicking on one segment, I can retrieve its index and the value without searching it in the list.

You can also use Data Recorder component to keep multiple datas. It works better with the Create Set component to delete repeated items.

1 Like

I also tried it, but it would be nice too keep everything with has little gh components in the canvas as possible withoud the need to storing the data in a component, to then display it to the Rhino viewport

Ok so I guess this will mean that I can skip all the GH part to display the selected objects on the Rhino viewport. Or atleast just have one component that is listening for mouse click events and internally storing each object to then display it to the vieport.

In theory you won’t need a component to do this, jsut loading a dll/gha in Grasshopper. You could observe all components at the end of a stream, retreive its internal geometric data and use this to calculate an intersection with mouse ray/line you get from mouse selection . This would be feasible, but it is a puzzle which will take some time. Is this what you are after?

Indeed it looks like it, it would have been nice if the rhino and grasshopper sdk would have made this more accessible. But probably it was not part of the design intention at the beginning.

hey , how are you doing ? any progress in this topic ? i’d wish to select interactively the points , curves … etc from the grasshoper geo all the deconstruction and lists thing it’s just a Fun Killer :sob::sob: , really , I’d wish grasshopper would be more like houdini in that sense … please help