<?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 : GET THE DISPLAYING COORDINATES OF A VIEWPORT OBJECT in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/get-the-displaying-coordinates-of-a-viewport-object/m-p/6049550#M37074</link>
    <description>&lt;P&gt;&lt;SPAN&gt;Hi Guilles, thanks for the answers&lt;/SPAN&gt;&lt;SPAN&gt;, it &lt;SPAN&gt;looks interesting&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt; &lt;SPAN&gt;I look forward to&lt;/SPAN&gt; &lt;SPAN&gt;reviewing... &lt;/SPAN&gt;but&lt;/SPAN&gt; &lt;SPAN&gt;I&amp;nbsp;&lt;SPAN&gt;have&lt;/SPAN&gt; &lt;SPAN&gt;another problem, I &lt;/SPAN&gt;could not&lt;/SPAN&gt; &lt;SPAN&gt;test &lt;/SPAN&gt;&lt;SPAN&gt;it&lt;/SPAN&gt; &lt;SPAN&gt;because I have my&lt;/SPAN&gt; &lt;SPAN&gt;installation of&lt;/SPAN&gt; &lt;SPAN&gt;AutoCAD&lt;/SPAN&gt; &lt;SPAN&gt;2016&lt;/SPAN&gt; &lt;SPAN&gt;was a&lt;/SPAN&gt; &lt;SPAN&gt;trial version and&lt;/SPAN&gt; &lt;SPAN&gt;expired&lt;/SPAN&gt; &lt;SPAN&gt;two days ago&lt;/SPAN&gt;&lt;SPAN&gt;, &amp;nbsp;:'-(&amp;nbsp; &amp;nbsp;Help!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 21 Feb 2016 19:34:09 GMT</pubDate>
    <dc:creator>inversiones_edgar_itriago</dc:creator>
    <dc:date>2016-02-21T19:34:09Z</dc:date>
    <item>
      <title>GET THE DISPLAYING COORDINATES OF A VIEWPORT OBJECT</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-the-displaying-coordinates-of-a-viewport-object/m-p/6048418#M37071</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Please I need Help!!! I hope that you may Help me..I have a Viewport rectangular object located in any paper space (layout1 for example) , which is displaying a certain area of the model space, I want to get the lower left and upper right coordinates (x,y) of that area I'm visualizing&amp;nbsp;with the&amp;nbsp;viewport object.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks in advance&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Feb 2016 22:52:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-the-displaying-coordinates-of-a-viewport-object/m-p/6048418#M37071</guid>
      <dc:creator>inversiones_edgar_itriago</dc:creator>
      <dc:date>2016-02-19T22:52:07Z</dc:date>
    </item>
    <item>
      <title>Re : GET THE DISPLAYING COORDINATES OF A VIEWPORT OBJECT</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-the-displaying-coordinates-of-a-viewport-object/m-p/6048658#M37072</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use these extension methods (from &lt;A href="https://www.theswamp.org/index.php?topic=31865.msg373672#msg373672" target="_blank"&gt;GeometryExtensions&lt;/A&gt;).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;

namespace GeometryExtensions
{
    /// &amp;lt;summary&amp;gt;
    /// Provides extension methods for the Viewport type.
    /// &amp;lt;/summary&amp;gt;
    public static class ViewportExtensions
    {
        /// &amp;lt;summary&amp;gt;
        /// Gets the transformation matrix from the specified model space viewport Display Coordinate System (DCS)
        /// to the World Coordinate System (WCS).
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name="vp"&amp;gt;The instance to which this method applies.&amp;lt;/param&amp;gt;
        /// &amp;lt;returns&amp;gt;The DCS to WDCS transformation matrix.&amp;lt;/returns&amp;gt;
        public static Matrix3d DCS2WCS(this Viewport vp)
        {
            return
                Matrix3d.Rotation(-vp.TwistAngle, vp.ViewDirection, vp.ViewTarget) *
                Matrix3d.Displacement(vp.ViewTarget - Point3d.Origin) *
                Matrix3d.PlaneToWorld(vp.ViewDirection);
        }

        /// &amp;lt;summary&amp;gt;
        /// Gets the transformation matrix from the World Coordinate System (WCS)
        /// to the specified model space viewport Display Coordinate System (DCS).
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name="vp"&amp;gt;The instance to which this method applies.&amp;lt;/param&amp;gt;
        /// &amp;lt;returns&amp;gt;The WCS to DCS transformation matrix.&amp;lt;/returns&amp;gt;
        public static Matrix3d WCS2DCS(this Viewport vp)
        {
            return vp.DCS2WCS().Inverse();
        }

        /// &amp;lt;summary&amp;gt;
        /// Gets the transformation matrix from the specified paper space viewport Display Coordinate System (DCS)
        /// to the paper space Display Coordinate System (PSDCS).
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name="vp"&amp;gt;The instance to which this method applies.&amp;lt;/param&amp;gt;
        /// &amp;lt;returns&amp;gt;The DCS to PSDCS transformation matrix.&amp;lt;/returns&amp;gt;
        public static Matrix3d DCS2PSDCS(this Viewport vp)
        {
            return
                Matrix3d.Scaling(vp.CustomScale, vp.CenterPoint) *
                Matrix3d.Displacement(vp.CenterPoint.GetAsVector()) *
                Matrix3d.Displacement(new Vector3d(-vp.ViewCenter.X, -vp.ViewCenter.Y, 0.0));
        }

        /// &amp;lt;summary&amp;gt;
        /// Gets the transformation matrix from the Paper Space Display Coordinate System (PSDCS)
        /// to the specified paper space viewport Display Coordinate System (DCS). 
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name="vp"&amp;gt;The instance to which this method applies.&amp;lt;/param&amp;gt;
        /// &amp;lt;returns&amp;gt;The PSDCS to DCS transformation matrix.&amp;lt;/returns&amp;gt;
        public static Matrix3d PSDCS2DCS(this Viewport vp)
        {
            return vp.DCS2PSDCS().Inverse();
        }
    }
}
&lt;/PRE&gt;
&lt;P&gt;Here's a testing command which draws a Polyline3d in the model space figuring the selected viewport extents.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using GeometryExtensions;
using AcAp = Autodesk.AutoCAD.ApplicationServices.Application;

[assembly: CommandClass(typeof(ViewportToWorldCoordinates.Commands))]

namespace ViewportToWorldCoordinates
{
    public class Commands
    {
        [CommandMethod("Test", CommandFlags.NoTileMode)]
        public void Test()
        {
            var doc = AcAp.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;

            var options = new PromptSelectionOptions();
            options.MessageForAdding = "\nSelect a viewport: ";
            options.SelectEverythingInAperture = true;
            options.SingleOnly = true;

            var filter = new SelectionFilter(new[] { new TypedValue(0, "VIEWPORT") });

            var selection = ed.GetSelection(options, filter);
            if (selection.Status != PromptStatus.OK)
                return;

            using (var tr = db.TransactionManager.StartTransaction())
            {
                var vp = (Viewport)tr.GetObject(selection.Value[0].ObjectId, OpenMode.ForRead);
                var extents = vp.GeometricExtents;
                var xform = vp.DCS2WCS() * vp.PSDCS2DCS();
                var vertices = new Point3dCollection();
                vertices.Add(extents.MinPoint.TransformBy(xform));
                vertices.Add(new Point3d(extents.MaxPoint.X, extents.MinPoint.Y, 0.0).TransformBy(xform));
                vertices.Add(extents.MaxPoint.TransformBy(xform));
                vertices.Add(new Point3d(extents.MinPoint.X, extents.MaxPoint.Y, 0.0).TransformBy(xform));
                Polyline3d pline = new Polyline3d(Poly3dType.SimplePoly, vertices, true);
                var modelSpace = (BlockTableRecord)tr.GetObject(
                    SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForWrite);
                modelSpace.AppendEntity(pline);
                tr.AddNewlyCreatedDBObject(pline, true);
                tr.Commit();
            }
        }
    }
}
&lt;/PRE&gt;</description>
      <pubDate>Sat, 20 Feb 2016 08:20:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-the-displaying-coordinates-of-a-viewport-object/m-p/6048658#M37072</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2016-02-20T08:20:57Z</dc:date>
    </item>
    <item>
      <title>Re : GET THE DISPLAYING COORDINATES OF A VIEWPORT OBJECT</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-the-displaying-coordinates-of-a-viewport-object/m-p/6049289#M37073</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's another testing command which draws a point (nodal) in paper space on the center of each circle entirely visible in the (rectangular) viewport.&lt;/P&gt;
&lt;P&gt;the command works whatever the model space current UCS and whatever the view in the viewport.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using GeometryExtensions;
using AcAp = Autodesk.AutoCAD.ApplicationServices.Application;

[assembly: CommandClass(typeof(TransSpacialTranformations.Commands))]

namespace TransSpacialTranformations
{
    public class Commands
    {
        [CommandMethod("CENTERMARK", CommandFlags.NoTileMode)]
        public void CenterMark()
        {
            var doc = AcAp.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;

            // switch to paper space if a viewport is activated
            if ((short)AcAp.GetSystemVariable("CVPORT") != 1)
                ed.SwitchToPaperSpace();

            // select a viewport
            var options = new PromptSelectionOptions();
            options.MessageForAdding = "\nSelect a rectangular viewport: ";
            options.SelectEverythingInAperture = true;
            options.SingleOnly = true;
            var filter = new SelectionFilter(new[] { new TypedValue(0, "VIEWPORT") });
            var selection = ed.GetSelection(options, filter);
            if (selection.Status != PromptStatus.OK)
                return;

            using (var tr = db.TransactionManager.StartTransaction())
            {
                // get the viewport extents (paper space coordinates)
                var vp = (Viewport)tr.GetObject(selection.Value[0].ObjectId, OpenMode.ForRead);
                var extents = vp.GeometricExtents;
                double x1 = extents.MinPoint.X, y1 = extents.MinPoint.Y;
                double x2 = extents.MaxPoint.X, y2 = extents.MaxPoint.Y;

                // activate the selected viewport
                ed.SwitchToModelSpace();
                AcAp.SetSystemVariable("CVPORT", vp.Number);

                // compute the transformation matrix from paper space coordinates to model space current UCS
                var wcs2ucs = ed.CurrentUserCoordinateSystem.Inverse();
                var psdcs2ucs = wcs2ucs * vp.DCS2WCS() * vp.PSDCS2DCS();

                // compute the model space UCS polygon vertices corresponding to the viewport extents
                var polygon = new Point3dCollection();
                polygon.Add(new Point3d(x1, y1, 0.0).TransformBy(psdcs2ucs));
                polygon.Add(new Point3d(x2, y1, 0.0).TransformBy(psdcs2ucs));
                polygon.Add(new Point3d(x2, y2, 0.0).TransformBy(psdcs2ucs));
                polygon.Add(new Point3d(x1, y2, 0.0).TransformBy(psdcs2ucs));

                // select circles within the polygon
                filter = new SelectionFilter(new[] { new TypedValue(0, "CIRCLE") });
                selection = ed.SelectWindowPolygon(polygon, filter);
                if (selection.Status != PromptStatus.OK)
                    return;

                // collect the selected circles centers transformed into paper space coordinates
                var centers = new Point3dCollection();
                var wcs2psdcs = vp.DCS2PSDCS() * vp.WCS2DCS();
                foreach (SelectedObject so in selection.Value)
                {
                    var circle = (Circle)tr.GetObject(so.ObjectId, OpenMode.ForRead);
                    centers.Add(circle.Center.TransformBy(wcs2psdcs));
                }

                // switch back to paper space
                ed.SwitchToPaperSpace();

                // add a point (nodal) in paper space on the center of the selected circles
                var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                foreach (Point3d pt in centers)
                {
                    DBPoint point = new DBPoint(pt);
                    curSpace.AppendEntity(point);
                    tr.AddNewlyCreatedDBObject(point, true);
                }

                tr.Commit();
            }
        }
    }
}
&lt;/PRE&gt;</description>
      <pubDate>Sun, 21 Feb 2016 10:57:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-the-displaying-coordinates-of-a-viewport-object/m-p/6049289#M37073</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2016-02-21T10:57:59Z</dc:date>
    </item>
    <item>
      <title>Re : GET THE DISPLAYING COORDINATES OF A VIEWPORT OBJECT</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-the-displaying-coordinates-of-a-viewport-object/m-p/6049550#M37074</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hi Guilles, thanks for the answers&lt;/SPAN&gt;&lt;SPAN&gt;, it &lt;SPAN&gt;looks interesting&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt; &lt;SPAN&gt;I look forward to&lt;/SPAN&gt; &lt;SPAN&gt;reviewing... &lt;/SPAN&gt;but&lt;/SPAN&gt; &lt;SPAN&gt;I&amp;nbsp;&lt;SPAN&gt;have&lt;/SPAN&gt; &lt;SPAN&gt;another problem, I &lt;/SPAN&gt;could not&lt;/SPAN&gt; &lt;SPAN&gt;test &lt;/SPAN&gt;&lt;SPAN&gt;it&lt;/SPAN&gt; &lt;SPAN&gt;because I have my&lt;/SPAN&gt; &lt;SPAN&gt;installation of&lt;/SPAN&gt; &lt;SPAN&gt;AutoCAD&lt;/SPAN&gt; &lt;SPAN&gt;2016&lt;/SPAN&gt; &lt;SPAN&gt;was a&lt;/SPAN&gt; &lt;SPAN&gt;trial version and&lt;/SPAN&gt; &lt;SPAN&gt;expired&lt;/SPAN&gt; &lt;SPAN&gt;two days ago&lt;/SPAN&gt;&lt;SPAN&gt;, &amp;nbsp;:'-(&amp;nbsp; &amp;nbsp;Help!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 21 Feb 2016 19:34:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-the-displaying-coordinates-of-a-viewport-object/m-p/6049550#M37074</guid>
      <dc:creator>inversiones_edgar_itriago</dc:creator>
      <dc:date>2016-02-21T19:34:09Z</dc:date>
    </item>
    <item>
      <title>Re : GET THE DISPLAYING COORDINATES OF A VIEWPORT OBJECT</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-the-displaying-coordinates-of-a-viewport-object/m-p/6049602#M37075</link>
      <description>&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class="hps"&gt;Sorry&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;but I can'&lt;/SPAN&gt;&lt;SPAN class="hps"&gt;t help you&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;for your&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;license&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;problem.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 21 Feb 2016 21:49:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-the-displaying-coordinates-of-a-viewport-object/m-p/6049602#M37075</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2016-02-21T21:49:12Z</dc:date>
    </item>
    <item>
      <title>Re : GET THE DISPLAYING COORDINATES OF A VIEWPORT OBJECT</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-the-displaying-coordinates-of-a-viewport-object/m-p/6365389#M37076</link>
      <description>&lt;P&gt;hello, I could test the code you suggested, it's perfect, thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jun 2016 20:59:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-the-displaying-coordinates-of-a-viewport-object/m-p/6365389#M37076</guid>
      <dc:creator>inversiones_edgar_itriago</dc:creator>
      <dc:date>2016-06-03T20:59:11Z</dc:date>
    </item>
  </channel>
</rss>

