c# - 在 AutoCAD 中获取实体的子实体顶点

标签 c# autocad

我正在尝试查找扫掠多段线的顶点。 所以我有一个实体,它是通过沿着 3D 折线扫过一个圆圈而创建的。 看起来像这样:image of sweeped solid

上周整个星期五我都在使用谷歌搜索,我想我必须尝试处理子实体部分。例如,我发现了如何更改子实体边缘的颜色,但天哪,我无法找到如何访问几何

这是我到目前为止尝试过的方法,但正如我在底部指出的那样,我有点迷路了:

    [CommandMethod("SubEntExample")]
    public void SubEntExample()
    {
        Document doc = Application.DocumentManager.MdiActiveDocument;
        Database db = doc.Database;
        Editor ed = doc.Editor;

        PromptEntityOptions peo = new PromptEntityOptions("\nSelect a 3D solid: ");
        peo.SetRejectMessage("\nInvalid selection...");
        peo.AddAllowedClass(typeof(Solid3d), true);

        PromptEntityResult per = ed.GetEntity(peo);

        if (per.Status != PromptStatus.OK)
            return;

        using (Transaction Tx = db.TransactionManager.StartTransaction())
        {
            Solid3d solid = Tx.GetObject(per.ObjectId, OpenMode.ForWrite) as Solid3d;

            ObjectId[] ids = new ObjectId[] { per.ObjectId };

            FullSubentityPath path = new FullSubentityPath(ids, new SubentityId(SubentityType.Null, IntPtr.Zero));

            List<SubentityId> subEntIds = new List<SubentityId>();

            using (Autodesk.AutoCAD.BoundaryRepresentation.Brep brep =
                new Autodesk.AutoCAD.BoundaryRepresentation.Brep(path))
            {                    
                foreach (Autodesk.AutoCAD.BoundaryRepresentation.Edge edge in brep.Edges)
                {
                    subEntIds.Add(edge.SubentityPath.SubentId);
                }                    
            }

            foreach (SubentityId subentId in subEntIds)
            {

                *** here i am lost ***

            }
            Tx.Commit();
        }
    }

最佳答案

我的第一个解决方案涉及获取所有的控制点并确定哪些是相关的,但多亏了互联网 (:) 的一些帮助,我想出了一个更好的解决方案

    /// <summary>
    /// Checks if there are boundaryreps that are marked as elliptical or circular arcs
    /// returns true if we found at least 2 of those points
    /// also stores the points in a referenced Point3dCollection
    /// </summary>
    /// <param name="solid"></param>
    /// <param name="pts"></param>
    /// <returns></returns>
    private bool GetSweepPathPoints(Solid3d solid, ref Point3dCollection pts)
    {
        // create boundary rep for the solid
        using (Brep brep = new Brep(solid))
        {
            // get edges of the boundary rep
            BrepEdgeCollection edges = brep.Edges;
            foreach (Edge edge in edges)
            {
                // get the nativ curve geometry of the edges and then 
                // check if it is a circle
                // for more info look at:
                // http://adndevblog.typepad.com/autocad/2012/08/retrieving-native-curve-geometry-using-brep-api.html
                Curve3d curv = ((ExternalCurve3d)edge.Curve).NativeCurve;
                if (curv is CircularArc3d)
                {
                    // transform curved arch into circle and add it to the colecction 
                    // (if not in it alreadz)
                    CircularArc3d circle = curv as CircularArc3d;
                    if (!pts.Contains(circle.Center)) pts.Add(circle.Center);
                }
            }
        }
        return (pts.Count > 1) ? true : false;
    }

然后我用下面的方式调用整个事情

            Point3dCollection pts = new Point3dCollection();
            // only do the whole thing if we face a swept solid
            if (GetSweepPathPoints(sld, ref pts))
            {
                for (int i = 0; i < pts.Count; i++)
                {
                    ed.WriteMessage("\nPt[{0}] = {1}", i, pts[i]);
                }
            }

关于c# - 在 AutoCAD 中获取实体的子实体顶点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40339131/

相关文章:

autocad - 如何处理dwg文件

c#, Autocad, 显示填充的属性

c# - 序列化代码导致未处理的异常

c# - 在 C# 上使用参数从一个数据库复制另一个数据库中的行

c# - 通过反射异步获取字段

autocad - 在折线附近画线

javascript - 来自 AutoCad 2011 的 XML 文件

c# - 在运行时创建一组两个 Div

c# - 返回按属性匹配的对象列表

c# - TextBlock 不会更新