I’m trying to add text exactly at the position of the mouse cursor.
But I’m having trouble getting the position where the mouse is on the Rhino screen
Below is my code.
Rhino.Display.RhinoView view = doc.Views.ActiveView;
Transform xform = view.ActiveViewport.GetTransform(
Point3d pt = new Point3d(?????.X, ?????.Y, 0.0);
Plane position = doc.Views.ActiveView.ActiveViewport.ConstructionPlane();
position.Origin = pt;
Guid te = doc.Objects.AddText("test", position, 7, "Arial", false, false);
Would someone have a solution for this?
If you are not going to use a GetPoint object to obtain a 3d point location, then you can Pinvoke the GetCursorPos Win32 function to get the current mouse cursor position. This is a 2d point, so you will need to transform it to a 3d point location using a screen-to-world coordinate transformation.
Is there no way to get X and Y of rhino screnn through rhinocommon?
No, not unless you are using a GetPoint object…
I am working on this, and I think it is now possible using this:
To get the captured point to be projected onto the construction plane, this seems to work:
screenPos = Rhino.UI.MouseCursor.Location;
clientPos = view.ScreenToClient(screenPos);
line = targetViewportInfo.GetFrustumLine(new System.Drawing.Point((int)clientPos.X, (int)clientPos.Y));
cplaneTarget = view.ActiveViewport.ConstructionPlane();
Rhino.Geometry.Intersect.Intersection.LinePlane(line, cplaneTarget, out tResult);
outPoint = line.PointAt(tResult);
You are replying to a 3+ year old topic for which the user has not been online since 2017
In my view, old posts should either be updated or taken down, if not then the post is misleading, i.e. “No, not unless you are using a GetPoint object…”