[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();
學習點:學習
一、文本的輸出,轉碼spa
二、用戶互交,關鍵字的使用3d
三、疑問點,明明沒有用pickfirst,爲何也有pickkfirst的效果????code