Getselection能不能接受keyword?

发布时间 2023-04-24 08:22:42作者: swtool

这个玩意绝对是个坑,CAD对Getselection的支持并不充分,需要通过keywordinput事件来弄,比较麻烦,而且很容易出问题。

所以我的做法是,不使用,哈哈!

下面这个是kean的代码:

    [CommandMethod("SELKW")]

    public void GetSelectionWithKeywords()
    {
      Document doc = AcadApp.DocumentManager.MdiActiveDocument;
      Editor ed = doc.Editor;
      PromptSelectionOptions pso = new PromptSelectionOptions();
      pso.Keywords.Add("FIrst");
      pso.Keywords.Add("Second");
      string kws = pso.Keywords.GetDisplayString(true);
      pso.MessageForAdding = "\nAdd objects to selection or " + kws;
      pso.MessageForRemoval = "\nRemove objects from selection or " + kws;
      pso.KeywordInput +=
        delegate (object sender, SelectionTextInputEventArgs e)
        {
          ed.WriteMessage("\nKeyword entered: {0}", e.Input);
        };
      PromptSelectionResult psr = ed.GetSelection(pso);
      if (psr.Status == PromptStatus.OK)
      {
        ed.WriteMessage("\n{0} object{1} selected.",
          psr.Value.Count,
          psr.Value.Count == 1 ? "" : "s"
        );
      }
    }