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);
    
                }
    
            }
  • 相关阅读:
    python_request中params和data
    python_多线程加锁
    python_多线程join和setDaemon
    python_faker模块
    python_jsonpath模块
    MyBatis-自定义结果映射规则
    MyBatis-SELECT基本查询
    MyBatis-参数处理
    MyBatis-mybatis全局映射文件解析
    MySQL高级-主从复制
  • 原文地址:https://www.cnblogs.com/swtool/p/3653063.html
Copyright © 2011-2022 走看看