CAD C# 根据点获其所在取闭合区域面积

前期在研究CAD的时候,想弄一个点击一个闭合区域内一点就获取这个区域的方法,后来尝试了使用boundary命令,可以实现。
现在把C#代码贴上来,希望对大家有用。
其中一个重要的环节就是调用CAD命令,这个借用了论坛里面一个高手的代码,不好意思忘了高手名字了。反正能够跳过boundary的回车控制。

效果如下:

 

代码如下:


[CommandMethod("boundaryCAD")]
        public void BoundaryCAD()
        {
            PromptPointOptions pPointOptions = new PromptPointOptions("\n 选择一个点");
            PromptPointResult pPointResult = pDocument.Editor.GetPoint(pPointOptions);
            if (pPointResult.Status == PromptStatus.OK)
            {
                Point3d point3d = pPointResult.Value;

                InvokeArx.Command(true"_Boundary", point3d, "\0");

                PromptSelectionResult pResult=  pDocument.Editor.SelectLast();
                SelectionSet pSelectionSet = pResult.Value;
                using (Transaction tran = pDatabase.TransactionManager.StartTransaction())
                {
                    foreach (ObjectId pObjectId in pSelectionSet.GetObjectIds())
                    {
                        Entity pEntity = tran.GetObject(pObjectId,OpenMode.ForWrite) as Entity;
                        if ((pEntity as Polyline) != null)
                        {
                            Polyline pPolyline = pEntity as Polyline;
                            pDocument.Editor.WriteMessage("\n当前区域面积是:" + pPolyline.Area.ToString());
                        }
                      pEntity.Erase(true);
                    }
                    tran.Commit();
                }
            }
        }


其中有个类的代码在附件里: /Files/tracyjfly/InvokeArx.rar
原文地址:https://www.cnblogs.com/tracyjfly/p/2601311.html