zoukankan      html  css  js  c++  java
  • CAD创建不规则形状视口

    选择CAD模型空间中多段线,在指定的布局中创建视口,方法如下:

     1         /// <summary>
     2         /// 创建视口
     3         /// </summary>
     4         /// <param name="roundLine">模型空间多段线</param>
     5         /// <param name="curentLayout">当前布局名称</param>
     6         /// <param name="insertPoint">布局空间视口插入点</param>
     7         /// <param name="scale">缩放比例</param>
     8         private void MakeViewport(Polyline roundLine, string curentLayout, Point3d insertPoint, double scale)
     9         {
    10             Database db = HostApplicationServices.WorkingDatabase;
    11             using (Transaction tran = db.TransactionManager.StartTransaction())
    12             {
    13                 BlockTable bt = tran.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
    14                 BlockTableRecord btr = tran.GetObject(bt[BlockTableRecord.PaperSpace], OpenMode.ForWrite) as BlockTableRecord;
    15                
    16                 Polyline bound =  roundLine.Clone() as Polyline;
    17                 bound.Closed = true;
    18                 Point3d maxPoint = bound.GeometricExtents.MaxPoint;
    19                 Point3d minPoint = bound.GeometricExtents.MinPoint;
    20                 Point3d centerPoint = new Point3d((maxPoint.X + minPoint.X) / 2, (maxPoint.Y + minPoint.Y) / 2, 0);
    21                 bound.TransformBy(Matrix3d.Scaling(scale, centerPoint));
    22                 bound.TransformBy(Matrix3d.Displacement(centerPoint.GetVectorTo(insertPoint)));
    23                 btr.AppendEntity(bound);
    24                 tran.AddNewlyCreatedDBObject(bound, true);
    25 
    26                 Viewport vp = new Viewport();
    27                 btr.AppendEntity(vp);
    28                 tran.AddNewlyCreatedDBObject(vp, true);
    29                 vp.NonRectClipEntityId = bound.Id;
    30 
    31                 vp.CenterPoint = insertPoint;  //视口插入位置
    32                 vp.ViewCenter = new Point2d(centerPoint.X, centerPoint.Y); //模型空间中心位置
    33 
    34                 vp.ViewHeight = maxPoint.Y - minPoint.Y; //模型空间高度
    35                 vp.Height = scale * vp.ViewHeight;  //视口高度
    36                 vp.NonRectClipOn = true;
    37                 vp.Locked = true;
    38                 vp.On = true;
    39                 tran.Commit();
    40             }
    41         }
  • 相关阅读:
    【bzoj2962】序列操作 线段树
    【bzoj1922】[Sdoi2010]大陆争霸 堆优化Dijkstra
    .NET Core / C# 开发 IOT 嵌入式设备的个人见解
    C#中Equals和= =(等于号)的比较)
    VS 2017常用快捷键
    【你不一定知晓的】C#取消异步操作
    工程实践:给函数取一个"好"的名字
    接口测试入门篇
    博客园知名博主 Vamei 英年早逝!
    人生苦短,我用 Python
  • 原文地址:https://www.cnblogs.com/oneday/p/3954385.html
Copyright © 2011-2022 走看看