C# CAD视图操作之缩放

mac2024-04-04  36

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。 本文链接:https://blog.csdn.net/adliy_happy/article/details/78770865 using System; using System.Collections.Generic; using System.Linq; using System.Text; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.Geometry;

/// ///  /// desc:视图操作类,缩放 /// auth:LYK /// date:2017/12/11 10:36:26 /// ///

namespace CadTool {     public static class ViewTableTools     {         ///         /// 实现视图的比例缩放         ///         ///         /// 缩放比例         public static void ZoomScaled(this Editor ed,double scale)         {             //得到当前视图             ViewTableRecord view = ed.GetCurrentView();             //修改视图的宽度和高度             view.Width /= scale;             view.Height /= scale;             //更新当前视图             ed.SetCurrentView(view);         }         ///         /// 实现视图的窗口缩放         ///         ///         /// 窗口角点         /// 窗口角点         public static void ZoomWindow(this Editor ed,Point3d pt1,Point3d pt2)         {             //创建一临时的直线用于获取两点表示的范围             using (Line line = new Line(pt1,pt2))             {                 //获取两点表示的范围                 Extents3d extents = new Extents3d(line.GeometricExtents.MinPoint, line.GeometricExtents.MaxPoint);                 //获取范围内的最小值点及最大值点                 Point2d minPt = new Point2d(extents.MinPoint.X, extents.MinPoint.Y);                 Point2d maxPt = new Point2d(extents.MaxPoint.X, extents.MaxPoint.Y);                 //得到当前视图                 ViewTableRecord view = ed.GetCurrentView();                 //设置视图的中心点、高度和宽度                 view.CenterPoint = minPt + (maxPt - minPt)/2;                 view.Height = maxPt.Y - minPt.Y;                 view.Width = maxPt.X - minPt.X;                 //更新当前视图                 ed.SetCurrentView(view);             }         }         ///         /// 根据图形边界显示视图         ///         ///         public static void ZoomExtens(this Editor ed)         {             Database db = ed.Document.Database;             //更新当前模型空间的范围             db.UpdateExt(true);             //根据当前图形的界限范围对视图进行缩放             if (db.Extmax.X < db.Extmin.X)             {                 Plane plane = new Plane();                 Point3d pt1 = new Point3d(plane, db.Limmin);                 Point3d pt2 = new Point3d(plane, db.Limmax);                 ed.ZoomWindow(pt1,pt2);             }             else             {                 ed.ZoomWindow(db.Extmin,db.Extmax);             }         }         ///         /// 根据对象的范围显示视图         ///         ///         /// 实体ID         public static void ZoomObject(this Editor editor,ObjectId objectId)         {             Database db = editor.Document.Database;             using (Transaction trans = db.TransactionManager.StartTransaction())             {                 //获取实体对象                 Entity entity = trans.GetObject(objectId, OpenMode.ForRead) as Entity;                 if (entity == null)                 {                     return;                  }                 //根据实体的范围对视图进行缩放                 Extents3d extents3 = entity.GeometricExtents;                 extents3.TransformBy(editor.CurrentUserCoordinateSystem.Inverse());                 editor.ZoomWindow(extents3.MinPoint, extents3.MaxPoint);                 trans.Commit();             }         }     } }

———————————————— 版权声明:本文为博主「adliy_happy」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/adliy_happy/article/details/78770865

最新回复(0)