SingleIdingCommand.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*-------------------------------------------------------------------------
  2. * 功能描述:IdingSingleCommand
  3. * 作者:xulisong
  4. * 创建时间: 2019/5/31 15:46:51
  5. * 版本号:v1.0
  6. * -------------------------------------------------------------------------*/
  7. using Autodesk.Revit.UI;
  8. using Autodesk.Revit.UI.Events;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. namespace FWindSoft.Revit
  15. {
  16. public class SingleIdingCommand : IRevitRegister
  17. {
  18. #region 初始化
  19. public SingleIdingCommand()
  20. {
  21. Enable = true;
  22. }
  23. public bool Enable { get; set; }
  24. #endregion
  25. #region 消费队列
  26. /// <summary>
  27. /// 对接事件绑定
  28. /// </summary>
  29. /// <param name="sender"></param>
  30. /// <param name="e"></param>
  31. protected virtual void ApplicaionIdling(object sender, IdlingEventArgs e)
  32. {
  33. if (!Enable)
  34. {
  35. return;
  36. }
  37. var application = sender as UIApplication;
  38. OnExecute(application);
  39. e.SetRaiseWithoutDelay();
  40. }
  41. #endregion
  42. protected virtual void OnExecute(UIApplication application)
  43. {
  44. Execute?.Invoke(this, application);
  45. }
  46. public event EventHandler<UIApplication> Execute;
  47. #region 事件注册相关
  48. public void Register(ExternalApplication application)
  49. {
  50. application.Idling += ApplicaionIdling;
  51. }
  52. public void Unregister(ExternalApplication application)
  53. {
  54. application.Idling -= ApplicaionIdling;
  55. }
  56. #endregion
  57. }
  58. }