zoukankan      html  css  js  c++  java
  • 一种将Region转为Polyline的方法

    在AutoCAD.NET二次开发中,如果要将面域转为Polyline主要有以下几种方式:

    1、使用Explode将面域炸成Line和Arc,然后再串起来,此方法可用于AutoCAD2007开始的所有版本。

    参考:http://through-the-interface.typepad.com/through_the_interface/2008/08/creating-a-seri.html

    2、想办法获取Region内的一个点,使用CAD的BO命令重新创建边界,并监听命令结束事件,获取最后一个生成的实体。

    3、使用C#和Lisp配合开发,在Lisp中使用bpoly创建边界。

    4、使用AutoCAD.NET接口中的Editor.TracBoundary方法取得新边界,但此方法从AutoCAD2011开始有。

    5、使用Brep和Edge来获取Region子实体,这几个接口从AutoCAD2009开始才添加进来的,

    使用Brep来取得Region的每条边,然后再将这些边转为弧和线段对象,再进行串联,示例代码如下:

    引用acdbmgdbrep.dll

    PromptEntityResult per = ed.GetEntity("
    请选择");
                if (per.Status == PromptStatus.OK)
                {
                    using (DocumentLock dlk = doc.LockDocument())
                    {
                        using (Transaction trans = db.TransactionManager.StartTransaction())
                        {
                            Entity ent = (Entity)trans.GetObject(per.ObjectId, OpenMode.ForWrite);
                            if (!(ent is Region))
                                return;
                            Region reg = (Region)ent;
                            Brep brep = new Brep(reg);
                            BrepEdgeCollection bec = brep.Edges;
                            if (bec != null)
                            {
                                foreach (Edge edge in bec)
                                {
                                    Curve3d cv3d = edge.Curve;
                                    ExternalCurve3d ecv3d = (ExternalCurve3d)cv3d;
                                    if (ecv3d.IsCircularArc)
                                    {
                                        CircularArc3d ca3d = ecv3d.NativeCurve as CircularArc3d;
                                        ed.WriteMessage("");
                                    }
                                    else if (ecv3d.IsLine)
                                    {
                                        ed.WriteMessage("
    线");
                                    }
                                    else if (ecv3d.IsLineSegment)
                                    {
                                        LineSegment3d ls3d = ecv3d.NativeCurve as LineSegment3d;
                                        ed.WriteMessage("
    线段");
                                    }
                                    else if (ecv3d.IsNativeCurve)
                                    {
                                        ed.WriteMessage("
    原始曲线");
                                    }
                                    else if (ecv3d.IsNurbCurve)
                                    {
                                        ed.WriteMessage("
    样条曲线");
                                    }
                                    else
                                    {
                                        ed.WriteMessage("
    " + ecv3d.ExternalCurveKind);
                                    }
                                    ed.WriteMessage("
    起点:" + cv3d.StartPoint.ToString() + "-终点:" + cv3d.EndPoint.ToString());
                                }
                            }
                        }
                    }
                }
  • 相关阅读:
    PAT顶级 1024 Currency Exchange Centers (35分)(最小生成树)
    Codeforces 1282B2 K for the Price of One (Hard Version)
    1023 Have Fun with Numbers (20)
    1005 Spell It Right (20)
    1092 To Buy or Not to Buy (20)
    1118 Birds in Forest (25)
    1130 Infix Expression (25)
    1085 Perfect Sequence (25)
    1109 Group Photo (25)
    1073 Scientific Notation (20)
  • 原文地址:https://www.cnblogs.com/bomb12138/p/5985600.html
Copyright © 2011-2022 走看看