欢迎加我的QQ群:193522571,一起来讨论、交流!

Getselection能不能接受keyword?

这个玩意绝对是个坑,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"
        );
      }
    }

 

posted @ 2023-04-24 08:18  swtool  阅读(31)  评论(0编辑  收藏  举报
欢迎加我的QQ群:193522571,一起来讨论、交流!