TheSwamp

Code Red => .NET => Topic started by: itcad on December 18, 2007, 08:34:14 PM

Title: How to use "Editor.PointToScreen " ?
Post by: itcad on December 18, 2007, 08:34:14 PM
How to use "Editor.PointToScreen " ?
Title: Re: How to use "Editor.PointToScreen " ?
Post by: Kerry on December 18, 2007, 10:31:54 PM

What have you tried ?
Title: Re: How to use "Editor.PointToScreen " ?
Post by: itcad on December 19, 2007, 02:22:44 AM

What have you tried ?


I want to  put cursor to a point3d.
Title: Re: How to use "Editor.PointToScreen " ?
Post by: David Hall on December 20, 2007, 09:49:14 AM
POst your code you have tried and we can see whats wrong
Title: Re: How to use "Editor.PointToScreen " ?
Post by: itcad on December 20, 2007, 07:55:34 PM
POst your code you have tried and we can see whats wrong

My code:
  Point3d pt = new Point3d(100, 200, 0);
Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
 Editor ed = doc.Editor;
int viewPortNumber = Convert.ToInt32(Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("cvport").ToString());
Cursor.Position = ed.PointToScreen(pt, viewPortNumber);

Run my code,Position of cursor  is different from the pt(100, 200, 0).
why?
Title: Re: How to use "Editor.PointToScreen " ?
Post by: It's Alive! on December 21, 2007, 02:04:22 AM

What have you tried ?


I want to  put cursor to a point3d.

Is this what you are looking for?

Code: [Select]
   [CommandMethod("Hola", CommandFlags.Modal)]
    public static void MyCommanderIsMyWife()
    {
      Editor ed = AcAp.Application.DocumentManager.MdiActiveDocument.Editor;
      int viewPortNumber = Convert.ToInt32(AcAp.Application.GetSystemVariable("CVPORT"));
      Point3d ToThePoint = ed.PointToWorld(System.Windows.Forms.Cursor.Position, viewPortNumber);
      ed.WriteMessage(ToThePoint.ToString());
    }

    [CommandMethod("Mola", CommandFlags.Modal)]
    public static void MyCommanderIsMyDaughter()
    {
      Editor ed = AcAp.Application.DocumentManager.MdiActiveDocument.Editor;
      int viewPortNumber = Convert.ToInt32(AcAp.Application.GetSystemVariable("CVPORT"));
      System.Drawing.Point ToThePoint = ed.PointToScreen(new Point3d(0, 0, 0), viewPortNumber);
      ed.WriteMessage(ToThePoint.ToString());
    }
Title: Re: How to use "Editor.PointToScreen " ?
Post by: sinc on December 21, 2007, 08:59:59 PM
I seem to be getting almost the correct result with the following.  Not exactly right, but close.  It also attempts to put the cursor on the point even if the point is not visible on-screen, which may result in a cursor that is way off the visible screen.

Code: [Select]
            Point3d pt = new Point3d(100, 200, 0);
            Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            int viewPortNumber = Convert.ToInt32(Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("cvport").ToString());
            System.Drawing.Point ptOffset = ed.PointToScreen(pt, viewPortNumber);
            System.Drawing.Point windowLocation = doc.Window.Location;
            Cursor.Position = new System.Drawing.Point(windowLocation.X + ptOffset.X, windowLocation.Y + ptOffset.Y);