Mouse position

I want to get the position of the mouse inside the rhino viewport as a Point3d without using the getpoint method. Actually, I want to track the mouse all the time. Would you mind to help me find a solution?

I assume you are working with RhinoCommon: in that case, you want to use the MouseCallback class. For documentation, see

Thanks for the response. Yes, I am using rhino common and C#. I have already visited this class, but I did not understand how to get the position of the mouse in the viewport. I think this class is used to add more functionality to the mouse. I also found a method called : ClientToWorld(). Do you have any suggestion on how to use this method?

I was able to Trackdown the solution to this point:

    System.Drawing.Point screenPos = System.Windows.Forms.Cursor.Position;
    Rhino.RhinoDoc doc = Rhino.RhinoDoc.ActiveDoc;
    RhinoView view = doc.Views.ActiveView;
    Line line = view.ActiveViewport.ClientToWorld(screenPos);
    Plane cplane = view.ActiveViewport.ConstructionPlane();
    double t;
    Rhino.Geometry.Intersect.Intersection.LinePlane(line, cplane, out t);
    A = line.PointAt(t);

The problem is that there This is not the absolute position in top view. So this is the question: How can i get the absolute postition? (10.4 KB)
Second, this is in 2D how can i get the 3d position?

you’ll need “screen to client” and “client to world”.

1 Like

Thanks that solved the 2D. I’ll attach the solution. (3.9 KB)

1 Like

for “3d” you need to do a raycast.Have a look at Intersect namespace or Ray class

1 Like

If you have a reference to the view port, you can use the frustum line. This is a line in world (model) coordinates that originates from the screen point. See this method and its overrides:

1 Like

Thankyou all, I used GetFrustumLine() and it workes perfectly for my task.