• AutoCAD.Net/C#.Net QQ群:193522571 点选多段线时取得当前多段线的两端点


    using Autodesk.AutoCAD.ApplicationServices;
        using Autodesk.AutoCAD.DatabaseServices;
        using Autodesk.AutoCAD.EditorInput;
        using Autodesk.AutoCAD.Runtime;
        using Autodesk.AutoCAD.Geometry;
        using Autodesk.AutoCAD.GraphicsInterface;
        using Autodesk.AutoCAD.Colors;
        //_____________________________________//
    
            [CommandMethod("colseg")]
            public void ColoredSegment()
            {
    
                Document doc = Application.DocumentManager.MdiActiveDocument;
    
                Database db = doc.Database;
    
                Editor ed = doc.Editor;
    
                PromptEntityOptions peo = new PromptEntityOptions("
    Select Segment of Polyline:");
    
                peo.SetRejectMessage("
    Must be a Polyline!");
    
                peo.AddAllowedClass(typeof(Autodesk.AutoCAD.Databa​seServices.Polyline), false);
    
                PromptEntityResult per = ed.GetEntity(peo);
    
                if (per.Status != PromptStatus.OK)
    
                    return;
    
                Transaction tr = db.TransactionManager.StartTransaction();
    
                Autodesk.AutoCAD.DatabaseServices.Polyline pl = new Autodesk.AutoCAD.DatabaseServices.Polyline();
    
                IntegerCollection ic = new IntegerCollection();
    
                using (tr)
                {
                    Autodesk.AutoCAD.DatabaseServices.Polyline pline = tr.GetObject(per.ObjectId, OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Polyline;
    
                    if (pline != null)
                    {
                        BlockTableRecord btr = (BlockTableRecord)tr.GetObject(pline.OwnerId, OpenMode.ForWrite);
    
                        double bulg = 0;
    
                        Point3d picked = pline.GetClosestPointTo((Point3d)per.PickedPoint, false);
    
                        double par = pline.GetParameterAtPoint(picked);
    
                        int m = (int)par;
    
                        Point2dCollection verts = new Point2dCollection(2);
    
                        SegmentType stype = pline.GetSegmentType(m);
    
                        if (stype == SegmentType.Arc)
                        {
                            CircularArc2d arc = pline.GetArcSegment2dAt(m);
    
                            bulg = pline.GetBulgeAt(m);
    
                            verts.Add(arc.StartPoint);
    
                            verts.Add(arc.EndPoint);
                        }
                        else if (stype == SegmentType.Line)
                        {
                            LineSegment2d ln = pline.GetLineSegment2dAt(m);
    
                            verts.Add(ln.StartPoint);
    
                            verts.Add(ln.EndPoint);
    
                            bulg = 0;
                        }
    
                        pl.AddVertexAt(0, verts[0], bulg, 0, 0);
    
                        pl.AddVertexAt(1, verts[1], 0, 0, 0);
    
                        pl.ColorIndex = 121;
    
                        ObjectIdCollection ids = new ObjectIdCollection();
    
                        btr.AppendEntity(pl);
    
                        tr.AddNewlyCreatedDBObject(pl, true);
    
                        verts = new Point2dCollection();
    
                        if (pl != null)
                        {
                            TransientManager tm = TransientManager.CurrentTransientManager;
                            tm.AddTransient(pl, TransientDrawingMode.Highlight, 128, ic);
    
                        }
                    }
    
                    if (pl != null)
                    {
                        pl.Erase();
    
                        pl.Dispose();// optional, might be removed
                    }
    
                    tr.Commit();
                    // pause for user input only
                    string key = ed.GetString("
    Press any key: ").StringResult;
    
                    TransientManager.CurrentTransientManager.EraseTran​sient(pline, ic);
    
                }
    
            }
  • 相关阅读:
    Android中的内部类引起的内存泄露
    Android的消息机制: Message/MessageQueue/Handler/Looper
    ArrayList/Vector的原理、线程安全和迭代Fail-Fast
    JVM中的Stack和Frame
    JVM中的垃圾收集算法和Heap分区简记
    无锁编程以及CAS
    简述Java内存模型的由来、概念及语义
    MQTT协议简记
    RabbitMQ的工作队列和路由
    RabbitMQ 入门
  • 原文地址:https://www.cnblogs.com/swtool/p/3653063.html
Copyright © 2020-2023  润新知