- 积分
- 4400
- 明经币
- 个
- 注册时间
- 2015-1-16
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 qq1254582201 于 2020-3-15 15:15 编辑
- [CommandMethod("CPP")]
- public void MakeVport()
- { Document dc = Application.DocumentManager.MdiActiveDocument;
- Database dtb = dc.Database;
- Transaction tr = dtb.TransactionManager.StartTransaction();
- var pl = Select("\n请选择多段线");
- var Scale = GetScale();
- Application.SetSystemVariable("TILEMODE", 0);
- dc.Editor.SwitchToPaperSpace();
- using (tr)
- {
- BlockTable bta = tr.GetObject(dtb.BlockTableId, OpenMode.ForRead) as BlockTable;
- BlockTableRecord btr = tr.GetObject(bta[BlockTableRecord.PaperSpace], OpenMode.ForWrite) as BlockTableRecord;
- Polyline newpl = pl.Clone() as Polyline;
- Point3d maxPoint = newpl.GeometricExtents.MaxPoint;
- Point3d minPoint = newpl.GeometricExtents.MinPoint;
- Point3d centerPoint = new Point3d((maxPoint.X + minPoint.X) / 2, (maxPoint.Y + minPoint.Y) / 2, 0);
- newpl.Closed = true;
- btr.AppendEntity(newpl);
- tr.AddNewlyCreatedDBObject(newpl, true);
- Viewport vp = new Viewport();
- btr.AppendEntity(vp);
- tr.AddNewlyCreatedDBObject(vp, true);
- vp.NonRectClipEntityId = newpl.Id;
- vp.CenterPoint = centerPoint; //视口插入位置
- var pt = new Point2d(centerPoint.X, centerPoint.Y);
- vp.ViewCenter = pt; //模型空间中心位置
- vp.ViewHeight = maxPoint.Y - minPoint.Y; //模型空间高度
- vp.Height = Scale * vp.ViewHeight; //视口高度
- vp.NonRectClipOn = true;
- vp.Locked = true;
- vp.On = true;
- tr.Commit();
- }
- }
- /// <summary>
- /// 选择多段线
- /// </summary>
- /// <param name="word">提示选择文字</param>
- /// <returns>多段线实体</returns>
- public static Polyline Select(string word)
- {
- Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
- Database db = doc.Database; Editor ed = doc.Editor;
- Polyline entity = null;
- PromptEntityResult ent = ed.GetEntity(word);
- if (ent.Status == PromptStatus.OK)
- {
- using (Transaction transaction = db.TransactionManager.StartTransaction())
- {
- entity = (Polyline)transaction.GetObject(ent.ObjectId, OpenMode.ForWrite, true);
- transaction.Commit();
- }
- }
- return entity;
- }
- /// <summary>
- /// 获取设定视口的比例
- /// </summary>
- /// <returns></returns>
- public double GetScale()
- {
- Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
- PromptDoubleOptions optDou = new PromptDoubleOptions ("\n请输入视口比例");
- optDou.AllowNegative=false;
- optDou.AllowZero=false;
- optDou.UseDefaultValue = true;
- optDou.DefaultValue = 1.00;
- PromptDoubleResult resDou = ed.GetDouble(optDou);
- if (resDou.Status == PromptStatus.OK)
- {
- double Scale = resDou.Value;
- return Scale;
- }
- else
- return 1.00;
- }
演示图片:
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注册
x
评分
-
查看全部评分
|