首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在AutoCAD中求实体的子实体顶点

在AutoCAD中求实体的子实体顶点
EN

Stack Overflow用户
提问于 2016-10-31 09:03:55
回答 1查看 1.5K关注 0票数 3

我试图找到一个横扫多边形的顶点点。因此,我有一个实体,它是通过沿着三维折线扫描一个圆圈来创建的。看起来是这样的:扫过固体图像

上周谷歌搜索了整个周五,我想我得玩一下这个子实体部分。例如,我找到了如何改变子实体边缘的颜色,但是为了手腕的缘故,我找不出如何访问几何图形。

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

代码语言:javascript
复制
    [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();
        }
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-11-03 09:15:57

我的第一个解决方案是掌握所有的方法,并决定哪些是相关的,但是感谢互联网的帮助( :)我想出了一个更好的解决方案

代码语言:javascript
复制
    /// <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;
    }

我把整件事按以下方式命名

代码语言:javascript
复制
            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]);
                }
            }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40339131

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档