/// <summary> 在命令行中获取一个字符 </summary> /// <param name="value">成功获得的数值</param> /// <returns>操作成功,则返回 true,操作失败或手动取消操作,则返回 false</returns> private static bool GetRegexPattern(Editor ed, out bool showtips, out bool ignoreCase, out string value) { value = ""; showtips = false; ignoreCase = false; var op = new PromptKeywordOptions("正则表达式") { AllowArbitraryInput = true, }; op.SetMessageAndKeywords(messageAndKeywords: "\n查询正则表达式[提示(T) / 不区分大小写(C)]:", globalKeywords: "提示 不区分大小写"); // 默认值写在前面 // var res = ed.GetKeywords(op); if (res.Status == PromptStatus.OK) { value = res.StringResult; if (value == "提示") { showtips = true; } else if (value == "不区分大小写") { ignoreCase = true; } else { return(true); } } return(false); }
/// <summary> 在命令行中获取一个字符 </summary> /// <param name="value">成功获得的数值</param> /// <returns>操作成功,则返回 true,操作失败或手动取消操作,则返回 false</returns> private static bool GetAnnotationsKey(Editor ed, out bool clearAnnots, out bool editInForm, out bool setNewValue, out string newAnnot) { clearAnnots = false; editInForm = false; setNewValue = false; newAnnot = ""; var op = new PromptKeywordOptions("元素注释编辑器") { AllowArbitraryInput = true, AllowNone = false, }; op.SetMessageAndKeywords(messageAndKeywords: "\n[清除注释(C) / 窗口编辑(F) / 设置新值(S)]:", globalKeywords: "K清除注释 K窗口编辑 K设置新值"); // 默认值写在前面 // var res = ed.GetKeywords(op); if (res.Status == PromptStatus.OK) { var key = res.StringResult; ed.WriteMessage("输入的值:" + key + "."); if (key == "K清除注释") { clearAnnots = true; } else if (key == "K窗口编辑") { editInForm = true; } else if (key == "K设置新值") { setNewValue = true; } else { // 输入的为一般字符,可以直接作为属性值 newAnnot = key; } return(true); } return(false); }
public void Main() { #if !DEBUG Statistic.SendCommandStarting(new ModPlusConnector()); #endif var doc = AcApp.DocumentManager.MdiActiveDocument; var db = doc.Database; var ed = doc.Editor; // Переменная "Копия" var isCopy = false; try { // Используем транзакцию var tr = db.TransactionManager.StartTransaction(); using (tr) { var opts = new PromptSelectionOptions(); opts.Keywords.Add(Language.GetItem(LangItem, "msg1")); var kws = opts.Keywords.GetDisplayString(true); opts.MessageForAdding = $"\n{Language.GetItem(LangItem, "msg2")}{kws}"; // Implement a callback for when keywords are entered opts.KeywordInput += (sender, e) => { if (e.Input.Equals(Language.GetItem(LangItem, "msg1"))) { isCopy = !isCopy; } }; var res = ed.GetSelection(opts); if (res.Status != PromptStatus.OK) { return; } var selSet = res.Value; var idArr = selSet.GetObjectIds(); if (idArr == null) { return; } var idArray = isCopy ? SetCopy(idArr) : idArr; var doubleOpt = new PromptDoubleOptions($"\n{Language.GetItem(LangItem, "msg3")}") { AllowNegative = false, AllowNone = false, AllowZero = false }; var doubleRes = ed.GetDouble(doubleOpt); if (doubleRes.Status != PromptStatus.OK) { return; } var pdOpt = new PromptKeywordOptions(string.Empty); var sVal = Language.GetItem(LangItem, "kw1"); // Начальное значение pdOpt.AllowArbitraryInput = true; pdOpt.AllowNone = true; // pdOpt.SetMessageAndKeywords( // "\n" + "Выберите базовую точку: " + "<" + sVal + // ">: " + "[Центр/ЛНиз/ЛВерх/ПНиз/ПВерх/СНиз/СВерх/СЛево/СПраво]", // "Центр ЛНиз ЛВерх ПНиз ПВерх СНиз СВерх СЛево СПраво"); pdOpt.SetMessageAndKeywords( $"\n{Language.GetItem(LangItem, "msg4")}<{sVal}>: [{Language.GetItem(LangItem, "kw1")}/{Language.GetItem(LangItem, "kw2")}/{Language.GetItem(LangItem, "kw3")}/{Language.GetItem(LangItem, "kw5")}/{Language.GetItem(LangItem, "kw4")}/{Language.GetItem(LangItem, "kw6")}/{Language.GetItem(LangItem, "kw7")}/{Language.GetItem(LangItem, "kw8")}/{Language.GetItem(LangItem, "kw9")}]", $"{Language.GetItem(LangItem, "kw1")} {Language.GetItem(LangItem, "kw2")} {Language.GetItem(LangItem, "kw3")} {Language.GetItem(LangItem, "kw5")} {Language.GetItem(LangItem, "kw4")} {Language.GetItem(LangItem, "kw6")} {Language.GetItem(LangItem, "kw7")} {Language.GetItem(LangItem, "kw8")} {Language.GetItem(LangItem, "kw9")}"); var promptResult = ed.GetKeywords(pdOpt); if (promptResult.Status != PromptStatus.OK) { return; } sVal = promptResult.StringResult; foreach (var objId in idArray) { var ent = (Entity)tr.GetObject(objId, OpenMode.ForWrite); var extPts = ent.GeometricExtents; var pt1 = extPts.MinPoint; var pt3 = extPts.MaxPoint; var pt = default(Point3d); if (sVal.Equals(Language.GetItem(LangItem, "kw1"))) { pt = new Point3d((pt1.X + pt3.X) / 2, (pt1.Y + pt3.Y) / 2, (pt1.Z + pt3.Z) / 2); } else if (sVal.Equals(Language.GetItem(LangItem, "kw2"))) { pt = pt1; } else if (sVal.Equals(Language.GetItem(LangItem, "kw3"))) { pt = new Point3d(pt1.X, pt3.Y, 0.0); } else if (sVal.Equals(Language.GetItem(LangItem, "kw4"))) { pt = pt3; } else if (sVal.Equals(Language.GetItem(LangItem, "kw5"))) { pt = new Point3d(pt3.X, pt1.Y, 0.0); } else if (sVal.Equals(Language.GetItem(LangItem, "kw6"))) { pt = new Point3d((pt1.X + pt3.X) / 2, pt1.Y, 0.0); } else if (sVal.Equals(Language.GetItem(LangItem, "kw7"))) { pt = new Point3d((pt1.X + pt3.X) / 2, pt3.Y, 0.0); } else if (sVal.Equals(Language.GetItem(LangItem, "kw8"))) { pt = new Point3d(pt1.X, (pt1.Y + pt3.Y) / 2, 0.0); } else if (sVal.Equals(Language.GetItem(LangItem, "kw9"))) { pt = new Point3d(pt3.X, (pt1.Y + pt3.Y) / 2, 0.0); } var mat = Matrix3d.Scaling(doubleRes.Value, pt); ent.TransformBy(mat); } tr.Commit(); } } catch (Exception ex) { ExceptionBox.Show(ex); } }
getUserInputKeyword(string deflt, out string result, string messageAndKeywords, string globalKeywords) { result = ""; bool escape = false; Editor ed = BaseObjs._editor; PromptKeywordOptions pko = new PromptKeywordOptions(messageAndKeywords); pko.AllowNone = true; pko.AppendKeywordsToMessage = true; pko.AllowArbitraryInput = true; string[] keyW = globalKeywords.Split(new Char[] { ' ' }); List <string> keys = new List <string>(); foreach (object s in keyW) { pko.Keywords.Add(s.ToString()); keys.Add(s.ToString()); } if (keys.Contains(deflt)) { pko.Keywords.Default = deflt; } else { pko.Keywords.Add(deflt); pko.Keywords.Default = deflt; } pko.SetMessageAndKeywords(messageAndKeywords, globalKeywords); PromptResult pr = ed.GetKeywords(pko); switch (pr.Status) { case PromptStatus.Cancel: escape = true; break; case PromptStatus.Error: escape = false; break; case PromptStatus.None: result = deflt; escape = false; break; case PromptStatus.OK: result = pr.StringResult; escape = false; break; case PromptStatus.Keyword: result = pr.StringResult; escape = false; break; } return(escape); }