Get Obj.GUID OnMouseHover (Advanced Rhino Options)

Hello,

I’ve been loving the hover highlighting exposed in the Rhino → Document Properties → Advanced tab.

My question is, how can I get the GUID of the object being hovered over by the mouse?

The option is called:

Rhino.Options.ChooseOneObject.DynamicHighlight

Which I have paired with the Silhouette Highlight for a more “Blender/Unreal Engine” style highlighting that I prefer:

Example here when hovered:
image

Example here when selected:
image

I am assuming that the hover highlight has to have some kind of method for detecting what object is being hovered on. Is this a method exposed in the API and if it is not, can it be please?

There’s so much one can do with this information.

I love the idea of being able to hover over objects, get the GUID, and then spawn contextual UI summary information or display conduits with info about the object near the object in screen space while the hover is active and then removing said visual elements when the hover ends.

Thanks for your response and help!

Hi @michaelvollrath, do you want this to happen always or when you prompt for an object or point ?

I have multiple scripts which come close, they are all subclassing GetPoint to prompt for a point snapped to an object. If the mouse is hovered / and snapped to and object, you can get the information using PointOnObject to get an ObjRef, then the Object and from this the Id. This works without actually clicking the point during the OnMouseMove event of the GetPoint method eg:

def OnMouseMove(self, e):
    obj_ref = e.Source.PointOnObject()
    if obj_ref:
        self.Text = obj_ref.Object().Id.ToString()
    else:
        self.Text = ""
        
    Rhino.Input.Custom.GetPoint.OnMouseMove(self, e)

You can then display the content of self.Text in the OnDynamicDraw event of the same GetPoint class…

_
c.

1 Like

Awesome, thank you @clement ! I believe this is what I am after. Yes I don’t want to have to click at all on any command but just have an “always on” (if the script is active) so ad i hover over objects with the mouse i can get their GUID and then perform any detailed function on that obj.

In Unreal Engine I would do this with a line trace from the viewport camera for a certain distance along the camera plane Z direction and anything this line would “hit” would give me the exactly obj type of what was hit and the point of where it was hit (the line | object intersection point)

I’m looking to replicate this behavior as it really comes in handy for a lot of UX features I’m trying to create.

Thanks for your help!!

And I need to use this in conjunction with a mouse callback, is that correct @clement ?

Here’s my code thus far:

#! python2

import Rhino
import Rhino.UI
import scriptcontext

class HoverMouseCallback(Rhino.UI.MouseCallback):
    def __init__(self):
        self.original_position = None
        self.mouse_moved = False

    def OnMouseMove(self, e):
        # current_position = Rhino.UI.MouseCursor.Location
        # Rhino.RhinoApp.WriteLine(current_position)
        obj_ref = e.Source.PointOnObject()
        if obj_ref:
            self.Text = obj_ref.Object().Id.ToString()
        else:
            self.Text = ""

        Rhino.RhinoApp.WriteLine(self.Text)
        print self.Text

        Rhino.Input.Custom.GetPoint.OnMouseMove(self, e)


def SetupMouseCallback():
    if scriptcontext.sticky.has_key('HoverMouseCallback'):
        callback = scriptcontext.sticky['HoverMouseCallback']
        if callback:
            callback.Enabled = False
            callback = None
            scriptcontext.sticky.Remove('HoverMouseCallback')
            Rhino.RhinoApp.WriteLine("Callback Removed")
    else:
        callback = HoverMouseCallback()
        callback.Enabled = True
        scriptcontext.sticky['HoverMouseCallback'] = callback
        Rhino.RhinoApp.WriteLine("Hover over object to get info...")

if __name__ == "__main__":
    SetupMouseCallback()

Hi @michaelvollrath, no you’ll need to subclass a GetPoint class for this as it will require that you actually snap to something while it asks for a point.

I’ve tried something similar, also using GetPoint which does not require snapping. It’s quite experimental and theoretically could be used with a MouseCallback too:

PickFrustumTest_BBox.py (2.9 KB)

Note that you’ll then have no OnDynamicDraw so you’ll either need to setup a conduit and draw the text there or alternatively position a form relative to the location of e.WindowPoint (which is e.ViewportPoint in case of a OnMouseMove of a MouseCallback).

_
c.

1 Like

Awesome! This is working great! I’ll play around and share the progress.

Thank you so much for sharing!

Yes, I think I will need to go the Display Conduit route for this.