zoukankan      html  css  js  c++  java
  • 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);
    
                }
    
            }
  • 相关阅读:
    我与计算机
    C高级第四次作业
    C高级第三次作业
    C高级第二次作业
    C高级第一次PTA作业 要求三
    C高级第一次PTA作业
    第0次作业
    # 20182304 实验七 《数据结构与面向对象程序设计》实验报告
    # 20182304 实验八 《数据结构与面向对象程序设计》实验报告
    # 20182304 《数据结构与面向对象程序设计》第八周学习总结
  • 原文地址:https://www.cnblogs.com/swtool/p/3653063.html
Copyright © 2011-2022 走看看