Is there a way to get osnap event in Rhino?

Just like the title, i m working on my own rhino command and i am stuck in getting the osnap event in Rhino: that is to say when a mouse click is happend to be an osnap point, how can i catch this event?

Hi @gw1119,

Rhino does not trigger an event when you osnap to something while picking a point. Why do you need this?

– Dale

Hi Dale, i would like to know the (x,y,z) number while an osnap mouse-click happens for my command need. or maybe my question should be that is there a way to get the x,y,z in Rhino coordinate once a mouse-click on geometric objects happens?

in addition to my question, is there a way to get the obj ID when an osnap type of mouse-click happens? for instance if i create a circle, then i click the centre of the circle by osnap to the curve obj, how can i get the crv obj’s ID once this happen?

In case anyone is looking for answers, I found out that if you project the snapped point to screen, the returned double number has many more digits than an unsnapped point. So you can set up an event yourself to watch when Osnap occurs.

var snappoint= e.Viewport.WorldToClient(e.Point);
Rhino.RhinoApp.WriteLine($"{snappoint.X.ToString().Length}");
// if OSnap is triggered, it returns with 16 digits

Hi @all,

just in case, there has been added an OsnapEventType to Rhino.Input.Custom.GetPoint probably after dale’s answer has been posted 3 years ago:

import Rhino

def DoSomething():
    
    gp = Rhino.Input.Custom.GetPoint()
    gp.SetCommandPrompt("Pick a point and snap to something")
    
    get_rc = gp.Get()
    if gp.CommandResult() == Rhino.Commands.Result.Success:
        print gp.OsnapEventType
        
DoSomething()

_
c.