<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: [.NET API] Convert screen coordinates to WCS like the status bar (works only in top view) in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/net-api-convert-screen-coordinates-to-wcs-like-the-status-bar/m-p/13390813#M497</link>
    <description>&lt;P&gt;In arx you could use acedTrans, I don’t know in .NET though. You can p/invoke it&lt;/P&gt;&lt;P&gt;&lt;A href="https://help.autodesk.com/view/OARX/2024/ENU/?guid=GUID-01A45BA0-CC4F-4DCA-840E-DCA8802A060A" target="_blank"&gt;https://help.autodesk.com/view/OARX/2024/ENU/?guid=GUID-01A45BA0-CC4F-4DCA-840E-DCA8802A060A&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 26 Mar 2025 03:54:52 GMT</pubDate>
    <dc:creator>daniel_cadext</dc:creator>
    <dc:date>2025-03-26T03:54:52Z</dc:date>
    <item>
      <title>[.NET API] Convert screen coordinates to WCS like the status bar (works only in top view)</title>
      <link>https://forums.autodesk.com/t5/net-forum/net-api-convert-screen-coordinates-to-wcs-like-the-status-bar/m-p/13390170#M496</link>
      <description>&lt;P&gt;Hi everyone ,&lt;/P&gt;&lt;P&gt;I'm developing a .NET plugin for AutoCAD (C#), and I'm trying to convert screen coordinates (from a drag &amp;amp; drop or mouse position) into WCS coordinates, exactly like the coordinates shown in the AutoCAD status bar when you move the mouse.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I use&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;Point3d world = doc.Editor.PointToWorld(screenPoint);&lt;/LI-CODE&gt;&lt;P&gt;this works perfectly in the top view, but gives unexpected results in 3D views.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have read several threads and tried many of the suggested solutions but non of then have worked.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My questions:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Is there a way to get the actual world coordinates under the cursor, like AutoCAD does internally?&lt;/LI&gt;&lt;LI&gt;How does the status bar compute the WCS position in real time?&lt;/LI&gt;&lt;LI&gt;What’s the correct way to convert a System.Drawing.point to a Point3D&amp;nbsp;in WCS ?&lt;/LI&gt;&lt;LI&gt;Any help or pointers would be much appreciated.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Tue, 25 Mar 2025 18:47:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/net-api-convert-screen-coordinates-to-wcs-like-the-status-bar/m-p/13390170#M496</guid>
      <dc:creator>s3b79</dc:creator>
      <dc:date>2025-03-25T18:47:59Z</dc:date>
    </item>
    <item>
      <title>Re: [.NET API] Convert screen coordinates to WCS like the status bar (works only in top view)</title>
      <link>https://forums.autodesk.com/t5/net-forum/net-api-convert-screen-coordinates-to-wcs-like-the-status-bar/m-p/13390813#M497</link>
      <description>&lt;P&gt;In arx you could use acedTrans, I don’t know in .NET though. You can p/invoke it&lt;/P&gt;&lt;P&gt;&lt;A href="https://help.autodesk.com/view/OARX/2024/ENU/?guid=GUID-01A45BA0-CC4F-4DCA-840E-DCA8802A060A" target="_blank"&gt;https://help.autodesk.com/view/OARX/2024/ENU/?guid=GUID-01A45BA0-CC4F-4DCA-840E-DCA8802A060A&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Mar 2025 03:54:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/net-api-convert-screen-coordinates-to-wcs-like-the-status-bar/m-p/13390813#M497</guid>
      <dc:creator>daniel_cadext</dc:creator>
      <dc:date>2025-03-26T03:54:52Z</dc:date>
    </item>
    <item>
      <title>Re: [.NET API] Convert screen coordinates to WCS like the status bar (works only in top view)</title>
      <link>https://forums.autodesk.com/t5/net-forum/net-api-convert-screen-coordinates-to-wcs-like-the-status-bar/m-p/13391804#M498</link>
      <description>&lt;P&gt;Have a look at &lt;A href="https://www.keanw.com/2015/12/determining-autocads-status-bar-coordinates-using-net.html" target="_blank" rel="noopener"&gt;this article&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Mar 2025 12:37:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/net-api-convert-screen-coordinates-to-wcs-like-the-status-bar/m-p/13391804#M498</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2025-03-26T12:37:08Z</dc:date>
    </item>
    <item>
      <title>Re: [.NET API] Convert screen coordinates to WCS like the status bar (works only in top view)</title>
      <link>https://forums.autodesk.com/t5/net-forum/net-api-convert-screen-coordinates-to-wcs-like-the-status-bar/m-p/13392654#M499</link>
      <description>&lt;P&gt;Thank you both for your answers.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I had already looked at &lt;A title="this article" href="https://www.keanw.com/2015/12/determining-autocads-status-bar-coordinates-using-net.html" target="_blank" rel="noopener"&gt;this article&lt;/A&gt; and given up because it did not work as I wanted..&lt;BR /&gt;I tested it again and I can say that yes, the coordinates returned are the ones I'm looking for.&lt;BR /&gt;But when Windows captures the mouse for drag and drop, the PointMonitor event is no longer raised... So...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'll try acedTrans and I'll come back here if my tries are successful.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Mar 2025 19:26:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/net-api-convert-screen-coordinates-to-wcs-like-the-status-bar/m-p/13392654#M499</guid>
      <dc:creator>s3b79</dc:creator>
      <dc:date>2025-03-26T19:26:10Z</dc:date>
    </item>
    <item>
      <title>Re: [.NET API] Convert screen coordinates to WCS like the status bar (works only in top view)</title>
      <link>https://forums.autodesk.com/t5/net-forum/net-api-convert-screen-coordinates-to-wcs-like-the-status-bar/m-p/13392823#M500</link>
      <description>&lt;P&gt;That was a bad suggestion (I didn't review it beforehand, and didn't notice the involvement of a PointMonitor, which obviously doesn't work very well).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Instead of that, have a look at &lt;A href="https://adndevblog.typepad.com/autocad/2013/08/get-mouse-cursor-position-without-event.html" target="_blank" rel="noopener"&gt;this article&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also note that when you're dealing with the active viewport, the problem isn't nearly as complicated as dragging over a paper space layout with multiple model space viewports. In that case you have to first use the screen point to get the model space viewport(s) that contain the mouse cursor (viewports can overlap which can make that much more complicated). Then you can use the viewport number to transform the screen coordinate to WCS).&lt;/P&gt;</description>
      <pubDate>Wed, 26 Mar 2025 21:43:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/net-api-convert-screen-coordinates-to-wcs-like-the-status-bar/m-p/13392823#M500</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2025-03-26T21:43:51Z</dc:date>
    </item>
    <item>
      <title>Re: [.NET API] Convert screen coordinates to WCS like the status bar (works only in top view)</title>
      <link>https://forums.autodesk.com/t5/net-forum/net-api-convert-screen-coordinates-to-wcs-like-the-status-bar/m-p/13400273#M501</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I finally found a solution in this &lt;A href="https://adndevblog.typepad.com/autocad/2013/02/how-to-get-the-mouse-cursor-coordinates-in-ucs.html" target="_blank" rel="noopener"&gt;blog post&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I'm pasting my code here for those who might be interested:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public static class AutoCadCoordinateHelper
{
    // https://adndevblog.typepad.com/autocad/2013/02/how-to-get-the-mouse-cursor-coordinates-in-ucs.html
    public static Point2d GetMousePositionInUcs(int screenX, int screenY)
    {
        var doc = Application.DocumentManager.MdiActiveDocument;
        var ed = doc.Editor;

        var pointInScreen = new Point(screenX, screenY);

        // Get point in DCS
        var pointInDcs = ed.PointToWorld(pointInScreen);

        // Convert to UCS
        var pointInUcs = AutoCadCoordinateTransformer.Transform(
            pointInDcs,
            AutoCadCoordinateTransformer.CoordinateSystem.Display,
            AutoCadCoordinateTransformer.CoordinateSystem.User);

        // Project to UCS XY plane
        var view = ed.GetCurrentView();
        var projectedPoint = view.ProjectToUcsXYPlane(pointInUcs);

        return new Point2d(projectedPoint.X, projectedPoint.Y);
    }
}

public static class AutoCadCoordinateTransformer
{
    private const int RTSHORT = 5003;
    private const int RTNORM = 5100;

    public enum CoordinateSystem
    {
        World = 0,
        User = 1,
        Display = 2,
        PaperSpace = 3
    }

    [DllImport("accore.dll", CallingConvention = CallingConvention.Cdecl)]
    private static extern int acedTrans(
        double[] point,
        IntPtr fromRb,
        IntPtr toRb,
        int disp,
        double[] result
    );

    public static Point3d Transform(Point3d point, CoordinateSystem from, CoordinateSystem to)
    {
        var result = new double[3];

        using var rbFrom = new ResultBuffer(new TypedValue(RTSHORT, (int)from));
        using var rbTo = new ResultBuffer(new TypedValue(RTSHORT, (int)to));

        var status = acedTrans(point.ToArray(), rbFrom.UnmanagedObject, rbTo.UnmanagedObject, 0, result);
        if (status != RTNORM)
            throw new InvalidOperationException("Coordinate transformation failed.");

        return new Point3d(result);
    }
}

public static class ViewExtensions
{
    public static Point3d ProjectToUcsXYPlane(this ViewTableRecord view, Point3d pointInUcs)
    {
        if (view == null)
            throw new ArgumentNullException(nameof(view));

        var ucsPlane = new Plane(Point3d.Origin, Vector3d.ZAxis);
        var direction = view.ViewDirection.GetNormal();

        return pointInUcs.Project(ucsPlane, direction);
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note that&amp;nbsp;&lt;STRONG&gt;PointToWorld&lt;/STRONG&gt;&amp;nbsp;adds a step to take into account the screen scale before calling &lt;STRONG&gt;acedCoordFromPixelToWorld.&lt;BR /&gt;&lt;BR /&gt;&lt;/STRONG&gt;Rather than calling &lt;STRONG&gt;acedtrans &lt;/STRONG&gt;I saw this &lt;A href="https://forums.autodesk.com/t5/net/translatecoordinates-to-dcs-net-c-vb/td-p/9666564" target="_blank" rel="noopener"&gt;post&lt;/A&gt; but didn't test it.&lt;BR /&gt;&lt;BR /&gt;Finally, I don't know if I could come up with anything simpler.&lt;/P&gt;</description>
      <pubDate>Mon, 31 Mar 2025 18:17:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/net-api-convert-screen-coordinates-to-wcs-like-the-status-bar/m-p/13400273#M501</guid>
      <dc:creator>s3b79</dc:creator>
      <dc:date>2025-03-31T18:17:19Z</dc:date>
    </item>
    <item>
      <title>Re: [.NET API] Convert screen coordinates to WCS like the status bar (works only in top view)</title>
      <link>https://forums.autodesk.com/t5/net-forum/net-api-convert-screen-coordinates-to-wcs-like-the-status-bar/m-p/13401346#M502</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/16023534"&gt;@s3b79&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I finally found a solution in this &lt;A href="https://adndevblog.typepad.com/autocad/2013/02/how-to-get-the-mouse-cursor-coordinates-in-ucs.html" target="_blank" rel="noopener"&gt;blog post&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note that&amp;nbsp;&lt;STRONG&gt;PointToWorld&lt;/STRONG&gt;&amp;nbsp;adds a step to take into account the screen scale before calling &lt;STRONG&gt;acedCoordFromPixelToWorld.&lt;/STRONG&gt;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;This looks like a re-invention of &lt;A href="https://help.autodesk.com/view/OARX/2025/ENU/?guid=OARX-ManagedRefGuide-Autodesk_AutoCAD_GraphicsSystem_View_WorldToDeviceMatrix" target="_blank" rel="noopener"&gt;View.WorldToDeviceMatrix&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Apr 2025 08:54:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/net-api-convert-screen-coordinates-to-wcs-like-the-status-bar/m-p/13401346#M502</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2025-04-01T08:54:14Z</dc:date>
    </item>
    <item>
      <title>Re: [.NET API] Convert screen coordinates to WCS like the status bar (works only in top view)</title>
      <link>https://forums.autodesk.com/t5/net-forum/net-api-convert-screen-coordinates-to-wcs-like-the-status-bar/m-p/13401410#M503</link>
      <description>&lt;P&gt;Yes, that's right.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But in the current implementation of &lt;STRONG&gt;PointToWorld&lt;/STRONG&gt; there is this extra step&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;pOINT = Autodesk.AutoCAD.ApplicationServices.Core.Application.ConvertToPixelCoords(pt);&lt;/LI-CODE&gt;&lt;P&gt;to take into account the scale factor of a monitor.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is not done in the original article, which could explain differences if some people try the two versions.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But that's a detail. Thanks again for your help.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Apr 2025 08:27:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/net-api-convert-screen-coordinates-to-wcs-like-the-status-bar/m-p/13401410#M503</guid>
      <dc:creator>s3b79</dc:creator>
      <dc:date>2025-04-01T08:27:28Z</dc:date>
    </item>
    <item>
      <title>Re: [.NET API] Convert screen coordinates to WCS like the status bar (works only in top view)</title>
      <link>https://forums.autodesk.com/t5/net-forum/net-api-convert-screen-coordinates-to-wcs-like-the-status-bar/m-p/13401424#M504</link>
      <description>&lt;P&gt;I noticed this in the python wrapper, not sure if would help, I use ScreenToClient with the doc window, maybe a hint&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;void PyEdUIContext::calcHitPoint()
{
    CPoint cursorPos;
    ::GetCursorPos(&amp;amp;cursorPos);
    ScreenToClient(adsw_acadDocWnd(), &amp;amp;cursorPos);

    acedDwgPoint cpt;
    acedCoordFromPixelToWorld(cursorPos, cpt);

    resbuf fromrb;
    fromrb.restype = RTSHORT;
    fromrb.resval.rint = 2; // DCS

    resbuf torb;
    torb.restype = RTSHORT;
    torb.resval.rint = 0; // WCS 

    acedTrans(cpt, &amp;amp;fromrb, &amp;amp;torb, FALSE, asDblArray(m_hitPoint));
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Apr 2025 08:44:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/net-api-convert-screen-coordinates-to-wcs-like-the-status-bar/m-p/13401424#M504</guid>
      <dc:creator>daniel_cadext</dc:creator>
      <dc:date>2025-04-01T08:44:07Z</dc:date>
    </item>
  </channel>
</rss>

