AutoCAD.Net/C#.Net QQ群:193522571 点选多段线时取得当前多段线的两端点
2014-04-08 22:00
731 查看
using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.Geometry; using Autodesk.AutoCAD.GraphicsInterface; using Autodesk.AutoCAD.Colors; //_____________________________________// [CommandMethod("colseg")] public void ColoredSegment() { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; PromptEntityOptions peo = new PromptEntityOptions("\nSelect Segment of Polyline:"); peo.SetRejectMessage("\nMust be a Polyline!"); peo.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Polyline), false); PromptEntityResult per = ed.GetEntity(peo); if (per.Status != PromptStatus.OK) return; Transaction tr = db.TransactionManager.StartTransaction(); Autodesk.AutoCAD.DatabaseServices.Polyline pl = new Autodesk.AutoCAD.DatabaseServices.Polyline(); IntegerCollection ic = new IntegerCollection(); using (tr) { Autodesk.AutoCAD.DatabaseServices.Polyline pline = tr.GetObject(per.ObjectId, OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Polyline; if (pline != null) { BlockTableRecord btr = (BlockTableRecord)tr.GetObject(pline.OwnerId, OpenMode.ForWrite); double bulg = 0; Point3d picked = pline.GetClosestPointTo((Point3d)per.PickedPoint, false); double par = pline.GetParameterAtPoint(picked); int m = (int)par; Point2dCollection verts = new Point2dCollection(2); SegmentType stype = pline.GetSegmentType(m); if (stype == SegmentType.Arc) { CircularArc2d arc = pline.GetArcSegment2dAt(m); bulg = pline.GetBulgeAt(m); verts.Add(arc.StartPoint); verts.Add(arc.EndPoint); } else if (stype == SegmentType.Line) { LineSegment2d ln = pline.GetLineSegment2dAt(m); verts.Add(ln.StartPoint); verts.Add(ln.EndPoint); bulg = 0; } pl.AddVertexAt(0, verts[0], bulg, 0, 0); pl.AddVertexAt(1, verts[1], 0, 0, 0); pl.ColorIndex = 121; ObjectIdCollection ids = new ObjectIdCollection(); btr.AppendEntity(pl); tr.AddNewlyCreatedDBObject(pl, true); verts = new Point2dCollection(); if (pl != null) { TransientManager tm = TransientManager.CurrentTransientManager; tm.AddTransient(pl, TransientDrawingMode.Highlight, 128, ic); } } if (pl != null) { pl.Erase(); pl.Dispose();// optional, might be removed } tr.Commit(); // pause for user input only string key = ed.GetString("\nPress any key: ").StringResult; TransientManager.CurrentTransientManager.EraseTransient(pline, ic); } }
相关文章推荐
- AutoCAD.Net/C#.Net QQ群:193522571 LinQ 已知字段名的字符串如何从一个表中取得这个字符串对应字段的所有记录
- AutoCAD.Net/C#.Net QQ群:193522571 LinQ获取当前查询结果的字段名,并且遍历各字段值
- AutoCAD.Net/C#.Net QQ群:193522571 WINFORM获取计算机名、域名、用户名和当前Mac地址
- AutoCAD.Net/C#.Net QQ群:193522571 对字符串进行四则运算
- AutoCAD.Net/C#.Net QQ群:193522571 将DataTable集合 B加入到DataTable A中,应用于两个或以上的只有单行数据的无主键的datatable的合并 Merge
- AutoCAD.Net/C#.Net QQ群:193522571 AutoCAD向命令栏发送命令
- AutoCAD.Net/C#.Net QQ群:193522571 利用反射将父类中的属性传递到子类中,实测效率不高
- AutoCAD.Net/C#.Net QQ群:193522571 c#链接到网址
- AutoCAD.Net/C#.Net QQ群:193522571 VS2013与cad调试时的问题
- AutoCAD.Net/C#.Net QQ群:193522571 AutoCAD中写状态栏status bar
- AutoCAD.Net/C#.Net QQ群:193522571 System.Drawing.Color和AutoDesk.AutoCAD.Colors.Color互转
- AutoCAD.Net/C#.Net QQ群:193522571 LinQ 两个集合求交集、并集
- AutoCAD.Net/C#.Net QQ群:193522571 将坐标系置为WCS
- AutoCAD.Net/C#.Net QQ群:193522571 点击对话框按钮去屏幕选择点或进行操作时,闪屏,已经解决!
- AutoCAD.Net/C#.Net QQ群:193522571 previewicon生成的块图标太小,CMLContentSearchPreviews生成大的图片
- AutoCAD.Net/C#.Net QQ群:193522571 多个框架共一套代码在进行迁移时的问题,properties,resource,未能加载文件或程序集“System.Drawing, Version=4.0.0.0
- AutoCAD.Net/C#.Net QQ群:193522571 从已有A.DWG中复制块BLK到新DWG中的方法
- AutoCAD.Net/C#.Net QQ群:193522571 删除编组(group) 尺寸线(dimension)
- AutoCAD.Net/C#.Net QQ群:193522571 遍历块属性值时,如何避免遍历到已经删除的属性?
- AutoCAD.Net/C#.Net QQ群:193522571 AutoCAD中状态栏