Ejemplo n.º 1
0
        /// <summary>
        /// Gets the transformation matrix from the paper space active viewport Display Coordinate System (DCS)
        /// to the Paper space Display Coordinate System (PSDCS).
        /// </summary>
        /// <param name="ed">The instance to which this method applies.</param>
        /// <returns>The DCS to PSDCS transformation matrix.</returns>
        /// <exception cref=" Autodesk.AutoCAD.Runtime.Exception">
        /// eNotInPaperSpace is thrown if this method is called form Model Space.</exception>
        /// <exception cref=" Autodesk.AutoCAD.Runtime.Exception">
        /// eCannotChangeActiveViewport is thrown if there is none floating viewport in the current layout.</exception>
        public static Matrix3d DCS2PSDCS(this Editor ed)
        {
            Database db = ed.Document.Database;

            if (db.TileMode)
            {
                throw new AcRx.Exception(AcRx.ErrorStatus.NotInPaperspace);
            }
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                Viewport vp =
                    (Viewport)tr.GetObject(ed.CurrentViewportObjectId, OpenMode.ForRead);
                if (vp.Number == 1)
                {
                    try
                    {
                        ed.SwitchToModelSpace();
                        vp = (Viewport)tr.GetObject(ed.CurrentViewportObjectId, OpenMode.ForRead);
                        ed.SwitchToPaperSpace();
                    }
                    catch
                    {
                        throw new AcRx.Exception(AcRx.ErrorStatus.CannotChangeActiveViewport);
                    }
                }
                return(vp.DCS2PSDCS());
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Gets the transformation matrix from the Paper Space Display Coordinate System (PSDCS)
 /// to the specified paper space viewport Display Coordinate System (DCS).
 /// </summary>
 /// <param name="vp">The instance to which this method applies.</param>
 /// <returns>The PSDCS to DCS transformation matrix.</returns>
 public static Matrix3d PSDCS2DCS(this Viewport vp)
 {
     return(vp.DCS2PSDCS().Inverse());
 }