tracyjfly
前期在研究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

分类:

技术点:

相关文章:

  • 2021-10-15
  • 2022-02-17
  • 2022-12-23
  • 2021-05-18
  • 2021-06-22
  • 2021-12-27
  • 2022-12-23
猜你喜欢
  • 2021-12-13
  • 2021-12-29
  • 2021-12-13
  • 2021-12-13
  • 2021-12-13
  • 2021-05-02
  • 2022-12-23
相关资源
相似解决方案