Button Mouse Event Again


I know already have some topics with this question, but I did not see any solution so I’ll come back to the question:

I need on while loop True, when the mouse button is clicked the break loop.

This work:
if scriptcontext.escape_test(False):

But I need break with mouse button.

Any help please.

I’ve subclassed this to intercept mouse events:

class MouseIntercept(R.UI.MouseCallback):
    def __init__(self):
        super(MouseIntercept, self).__init__()
    def OnMouseDown(self, e):
    def OnMouseUp(self, e):
    def OnMouseMove(self, e):

If you are in a loop I don’t know if the callback will work like the escape test though.

Thank you for you replay.

I dont understand, How can I implement it?


Can you provide some details about what you are trying to do? There may be a better approach.

Hello Steve,

I’m basically re-creating a command to do this:

Surface= rs.GetObject(“get surface”,8)
while True:

    cursor = rs.GetCursorPos()
    translation = cursor[0]- cursor2[0]
    cursor2 = rs.GetCursorPos()
    rs.MoveObject(Surface, translation)

    if scriptcontext.escape_test(False):
        print "esc"

I just need to access the mouse button to place the obj (exit the loop),
and eventually also access the mouse wheel to rotate the object.


This is what the GetPoint class in RhinoCommon is for.

Sorry for my ignorance Steve, but, I can not see how this command can help me.

My script, get a surface and and follow the position of the mouse wherever it goes, I just need
when press the mouse button exit the loop.

This is the first phase, then I have to complete the script to automatically snap other objects (I already have an idea how to do)


I’ll have to write up a sample for using GetPoint to do this then. I won’t be able to get to this today, sorry

Thank you

Hello @stevebaer is possible write this sample?

Ok, I find one solution with mousecallback function, but now
I have the problem that the event “OnMouseUp” is triger for the two mouse keys,
left and right click.

I see online doc:

I dont see any reference to left and right click, or the wheel event.

There is any of this args?


– Dale

Hello @dale , I iam using python:

import rhinoscriptsyntax as rs
import Rhino

class MyMouseCallback(Rhino.UI.MouseCallback):

def OnMouseDown(self, e):
    print "Down"
def OnMouseUp(self, e):
    print "up"        

def RunCommand():
m_mc = MyMouseCallback()
m_mc.Enabled = True

Rhino.RhinoApp.WriteLine("Click somewhere in a viewport ...")
return Rhino.Commands.Result.Success


How I put OnMouseDown (args) on python??

Fun with mouse buttons…

import System
import Rhino
import scriptcontext as sc

class SampleMouseCallback(Rhino.UI.MouseCallback):
  def OnMouseDown(self, e):
    print "OnMouseDown", e.Button
def TestSampleMouseCallback():
    if sc.sticky.has_key('TestSampleMouseCallback'):
        callback = sc.sticky['TestSampleMouseCallback']
        if callback:
            callback.Enabled = False
            callback = None
        callback = SampleMouseCallback()
        callback.Enabled = True
        sc.sticky['TestSampleMouseCallback'] = callback
        Rhino.RhinoApp.WriteLine("Click somewhere...")

if __name__ == "__main__":

– Dale

1 Like

If you are trying to draw preview geometry moving around the screen with features like snapping, the mouse callback is not the route to take. This is morein line with GetPoint operations or transform commands. Sorry I haven’t written a sample yet.

Hello @stevebaer,

I dont now if I can say that my function is the same of “draw preview geometry”.

I whant make script that move one obj, and snap all vertices to all other objs vertices on the document,
the snap is not just for mouse point, at same time the snap was to have a offset tickness from the other

I alreday have the script running, snaping to all vertices with offset distance:

Now I need breack the loop on mouse clic to place the obj, and I need to , acess to keyboad keys during
the while loop to , ex: rotate the selected obj or some other funcions.

This is what I trying make:

My loop is continually looking for the vertices to snap, I can not interrupt the loop, if is interrupt whit “pause”
or something else, stop to compare vertives in the document.

@dale ,

Any change to have the same function for the keyboard keys??, any KeyCallBack?

I dont find any read key function on Ironpython.

Hi @MatrixRatrix,

Sorry, RhinoCommon doesn’t have special tools for manipulating the keyboard.

– Dale