明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 723|回复: 4

C#中如何实现先选择的pickfirst选择集按下ESC键清除选择集并且触发对Combobox

[复制链接]
发表于 2019-12-27 23:13 | 显示全部楼层 |阅读模式
C#中如何实现先选择的pickfirst选择集按下ESC键清除选择集并且触发对Combobox控制内容列表清空,如下图所示:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
发表于 2019-12-28 01:35 | 显示全部楼层
在Pycad里试了下,下面的代码是可行的
  1. _esc = False
  2. _num = 0

  3. def pickfirst_added(ed, e):
  4.     if e.Flags == aced.SelectionFlags.PickfirstSet:
  5.         global _esc, _num
  6.         if _esc:
  7.             _esc = False
  8.             _num -= (e.Selection.Count + e.AddedObjects.Count)
  9.         else:
  10.             _num = e.Selection.Count + e.AddedObjects.Count
  11.         ed.WriteMessage("\n%s" % _num)

  12. def pickfirst_removed(ed, e):
  13.     if e.Flags == aced.SelectionFlags.PickfirstSet:
  14.         global _num
  15.         _num = e.Selection.Count - e.RemovedObjects.Count
  16.         ed.WriteMessage("\n%s" % _num)

  17. def on_message(sender, e):
  18.     m = e.Message
  19.     if (m.message == 0x0100) and (int(m.wParam) & 65535 == 27):
  20.         global _esc
  21.         _esc = True

  22. @command()
  23. def showpickfirstinfo(doc):
  24.     ed = doc.Editor  #type: aced.Editor
  25.     ed.SelectionAdded += pickfirst_added
  26.     ed.SelectionRemoved += pickfirst_removed
  27.     acap.Core.Application.PreTranslateMessage += on_message

  28. @command()
  29. def unshowpickfirstinfo(doc):
  30.     ed = doc.Editor  #type: aced.Editor
  31.     ed.SelectionAdded -= pickfirst_added
  32.     ed.SelectionRemoved -= pickfirst_removed
  33.     acap.Core.Application.PreTranslateMessage -= on_message
复制代码
发表于 2019-12-28 12:52 | 显示全部楼层
本帖最后由 雪山飞狐_lzh 于 2019-12-28 22:00 编辑

好吧 感觉我想多了。。。ImpliedSelectionChanged事件就可以 奇怪我昨天这样写怎么总不行?
  1. def pickfirst_changed(sender, e):
  2.     #事件的触发者即当前文档
  3.     ed = sender.Editor  #type: aced.Editor
  4.     #获取PickFirst选择集
  5.     res = ed.SelectImplied()
  6.     if res.Status == aced.PromptStatus.OK:
  7.         ed.WriteMessage(str(res.Value.Count))
  8.     else:
  9.         ed.WriteMessage("0")

  10. def doc_created(sender, e):
  11.     #新文档创建后,绑定ImpliedSelectionChanged事件
  12.     e.Document.ImpliedSelectionChanged += pickfirst_changed

  13. @command()
  14. def showpickfirstinfo(doc):
  15.     #获取文档集合
  16.     docs = acap.Application.DocumentManager
  17.     #绑定DocumentCreated事件
  18.     docs.DocumentCreated += doc_created
  19.     for d in docs:
  20.         #遍历已有文档,绑定ImpliedSelectionChanged事件
  21.         d.ImpliedSelectionChanged += pickfirst_changed

  22. @command()
  23. def unshowpickfirstinfo(doc):
  24.     docs = acap.Application.DocumentManager
  25.     docs.DocumentCreated -= doc_created
  26.     for d in docs:
  27.         d.ImpliedSelectionChanged -= pickfirst_changed
复制代码
 楼主| 发表于 2019-12-28 21:09 | 显示全部楼层
用C#来写,这个不太明白
发表于 2019-12-28 22:01 | 显示全部楼层
简单注释了一下。。。话说我觉得pycad的代码和C#相差不大
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-6-18 14:39 , Processed in 0.152100 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表