码迷,mamicode.com
首页 > Web开发 > 详细

CAD.net 二次开发--输出点名和点坐标,点类型

时间:2016-07-24 17:42:57      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:

[CommandMethod("aa", CommandFlags.UsePickSet)]
        public void aa()
        {
            Database db = HostApplicationServices.WorkingDatabase;
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            // PromptSelectionOptions opt = new PromptSelectionOptions("\n请选择点名和点的牵引线");
            PromptSelectionResult psr = ed.GetSelection();
            if (psr.Status != PromptStatus.OK) return;
            SelectionSet ss = psr.Value;
            if (ss.Count != 2) { ed.WriteMessage("请选择 点名 和 点的牵引线"); return; }
            string pointname = "";
            string pointtype = "";
            Point3d pout = new Point3d();
            Polyline pointpl = new Polyline();
            Point3dCollection points = new Point3dCollection();
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                foreach (ObjectId id in ss.GetObjectIds())
                {
                    DBText text = trans.GetObject(id, OpenMode.ForRead) as DBText;
                    if (text != null) pointname = text.TextString;
                    Polyline pl = trans.GetObject(id, OpenMode.ForRead) as Polyline;
                    if (pl != null)
                    {
                        pointpl = pl;
                        for (int i = 0; i < pl.NumberOfVertices; i++)
                        {
                            points.Add(pl.GetPoint3dAt(i));
                        }
                    }

                }
                trans.Commit();
            }
            if (points.Count != 3) { ed.WriteMessage("请确保点的牵引线正确,是否仅有3个节点"); }
            if (points[0].Y == points[1].Y) { pout = points[2]; }

            if (points[0].Y == points[2].Y) { pout = points[1]; }

            if (points[1].Y == points[2].Y) { pout = points[0]; }
            else { ed.WriteMessage("请确保点的引线有一端水平"); return; }
            ///////导出点类型
            PromptKeywordOptions pkey = new PromptKeywordOptions("\n请选择点类型[弯头(1)/阀门(2)/直线点(3)/三通(4)/变颈(5)/上下翻(6)/其他(7)]<1>");
            pkey.Keywords.Add("1");
            pkey.Keywords.Add("2");
            pkey.Keywords.Add("3");
            pkey.Keywords.Add("4");
            pkey.Keywords.Add("5");
            pkey.Keywords.Add("6");
            pkey.Keywords.Add("7");
            pkey.Keywords.Default = "1";
            pkey.AppendKeywordsToMessage = false;
            here:
            PromptResult pr = ed.GetKeywords(pkey);
            //ed.WriteMessage("输入关键字"+pr.StringResult);
           
                switch (pr.StringResult)
                {
                    case "1":
                        pointtype = "弯头";
                        //ed.WriteMessage("hhhhhhhhhhhhhhhhhhhhhhh");
                        ed.WriteMessage("\n您选择的点类型为:"+pointtype);
                        break;
                    case "2":
                        pointtype = "阀门";
                        ed.WriteMessage("\n您选择的点类型为:" + pointtype);
                        break;
                    case "3":
                        pointtype = "直线点";
                        ed.WriteMessage("\n您选择的点类型为:" + pointtype);
                        break;
                    case "4":
                        pointtype = "三通";
                        ed.WriteMessage("\n您选择的点类型为:" + pointtype);
                        break;
                    case "5":
                        pointtype = "变径";
                        ed.WriteMessage("\n您选择的点类型为:" + pointtype);
                        break;
                    case "6":
                        pointtype = "上下翻";
                        ed.WriteMessage("\n您选择的点类型为:" + pointtype);
                        break;
                    case "7":
                        ed.WriteMessage("\n您选择的点类型为:空值");
                        break;
                    default:


                        ed.WriteMessage("\n输入了无效关键字,请重新输入:");
                      //  break;
                     goto here;
               
            }
            //ed.WriteMessage(pointtype);
            //////结果的输出///////////////
            string path = "D:\\新输出点.csv";
            FileStream fs = new FileStream(path, FileMode.Append);
            StreamWriter sw = new StreamWriter(fs,Encoding.GetEncoding("gb2312"));
            sw.WriteLine(pointname + "," + pout.X.ToString() + "," + pout.Y.ToString() + "," + pointtype);
            sw.Close();
            fs.Close();

学习点:

1、文本的输出,转码

2、用户互交,关键字的使用

3、疑问点,明明没有用pickfirst,为什么也有pickkfirst的效果????

CAD.net 二次开发--输出点名和点坐标,点类型

标签:

原文地址:http://www.cnblogs.com/w-lumi/p/5701062.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!