AutoCAD二次开发(.Net)之多重引线(MLeader)创建
2017-12-29 10:06
645 查看
using System; using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.Geometry; using Autodesk.AutoCAD.EditorInput; [CommandMethod("CREATEMLEADER")] public void CreateMLeader() { Document doc = Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; Database db = doc.Database; const string arrowName = "_DOT"; ObjectId arrId = GetArrowObjectId(arrowName); // Get the start point of the leader PromptPointResult result =ed.GetPoint("/n 选择标注起始位置: " ); if (result.Status != PromptStatus.OK) return; Point3d startPt = result.Value; // Get the end point of the leader PromptPointOptions opts =new PromptPointOptions("/n选择标注终止位置: "); opts.BasePoint = startPt; opts.UseBasePoint = true; result = ed.GetPoint(opts); if (result.Status != PromptStatus.OK) return; Point3d endPt = result.Value; Transaction tr =db.TransactionManager.StartTransaction(); using (tr) { try { BlockTable bt =(BlockTable)tr.GetObject(db.BlockTableId,OpenMode.ForRead); BlockTableRecord btr = (BlockTableRecord)tr.GetObject( bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite ); // Create the MLeader MLeader mld = new MLeader(); int ldNum = mld.AddLeader(); int lnNum = mld.AddLeaderLine(ldNum); mld.AddFirstVertex(lnNum, startPt); mld.AddLastVertex(lnNum, endPt); mld.ArrowSymbolId = arrId; mld.LeaderLineType = LeaderType.SplineLeader; // Create the MText MText mt = new MText(); mt.Contents = "ABC"; mt.Location = endPt; mld.ContentType = ContentType.MTextContent; mld.MText = mt; // Add the MLeader btr.AppendEntity(mld); tr.AddNewlyCreatedDBObject(mld, true); tr.Commit(); } catch { // Would also happen automatically // if we didn't commit tr.Abort(); } } } static ObjectId GetArrowObjectId(string newArrName) { ObjectId arrObjId = ObjectId.Null; Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; // Get the current value of DIMBLK string oldArrName = Application.GetSystemVariable("DIMBLK") as string; // Set DIMBLK to the new style // (this action may create a new block) Application.SetSystemVariable("DIMBLK", newArrName); // Reset the previous value of DIMBLK if (oldArrName.Length != 0) Application.SetSystemVariable("DIMBLK", oldArrName); // Now get the objectId of the block Transaction tr = db.TransactionManager.StartTransaction(); using (tr) { BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead); arrObjId = bt[newArrName]; tr.Commit(); } return arrObjId; }
相关文章推荐
- AutoCAD二次开发(.Net)之创建图层Layer
- AutoCAD二次开发(.Net)之多文本(MText)创建
- .NET AutoCAD二次开发之路(四、文字篇)
- AutoCAD二次开发之创建菜单
- AutoCAD二次开发(.Net)之LSP变量赋值
- AutoCAD .Net 二次开发 VisualStudio 及 .Net Framework 选择
- AutoCAD.net/Map 3D/AIMS/MapGuide/Civil 3D二次开发学习指南
- C#.NET平台的AutoCAD二次开发
- AutoCAD二次开发(.Net)之块的操作(获取名称、修改名称)
- 发布一个ObjectARX .NET AutoCAD 二次开发 添加各种实体的类
- AutoCAD二次开发(.Net)之多边形交叉选择
- AutoCAD二次开发(C#.Net)之字符串转换成ObjectId
- AutoCAD二次开发(.Net)之DBDictionary信息的添加与获取
- AutoCAD.NET 二次开发(一) 自定义菜单及自动加载
- AutoCAD二次开发(.Net)之设置MText字体(1)
- .NET AutoCAD二次开发之路(三、圆弧篇)
- AutoCAD .NET API二次开发学习指南
- AutoCAD.NET 二次开发(二) 自动替换缺失字体
- AutoCad .NET(C#) 二次开发
- AutoCAD二次开发——AutoCAD.NET API开发环境搭建