123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- using Autodesk.Revit.UI;
- namespace FWindSoft.Revit
- {
- /*
- * 验证是否是同步,不是同步的话,则需要提供回调函数
- */
- /// <summary>
- /// 扩展事件
- /// </summary>
- public class ExternalEventCommand
- {
- public ExternalEventCommand(RevitHandler handler) : this(handler, true)
- {
- }
- public ExternalEventCommand(RevitHandler handler, bool createRefCommand)
- {
- Handler = handler;
- if (createRefCommand)
- {
- CreateEvent();
- }
- }
- /// <summary>
- /// 命令实际处理者
- /// </summary>
- public RevitHandler Handler { get; private set; }
- /// <summary>
- /// 生成Event
- /// </summary>
- /// <returns></returns>
- public ExternalEvent CreateEvent()
- {
- if (Handler != null && Event == null)
- {
- Event = ExternalEvent.Create(Handler);
- }
- return Event;
- }
- #region 关联扩展事件
- /// <summary>
- /// 扩展事件的命令
- /// </summary>
- public ExternalEvent Event { get; private set; }
- /// <summary>
- /// 触发命令
- /// </summary>
- /// <returns></returns>
- public ExternalEventRequest Raise()
- {
- #region 如果关联命令为空,创建一次
- if (Event == null)
- {
- CreateEvent();
- }
- #endregion
- if (Event == null)
- {
- return ExternalEventRequest.Pending;
- }
- return Event.Raise();
- }
- /// <summary>
- /// 根据指定参数触发命令
- /// </summary>
- /// <param name="parameter">传入参数,在回调方法参数中可以找打使用</param>
- /// <returns></returns>
- public ExternalEventRequest Raise(object parameter)
- {
- if (Handler != null)
- {
- Handler.Parameter = parameter;
- }
- #region 如果关联命令为空,创建一次
- if (Event == null)
- {
- CreateEvent();
- }
- #endregion
- if (Event == null)
- {
- return ExternalEventRequest.Pending;
- }
- return Event.Raise();
- }
- #endregion
- #region 析构处理
- ~ExternalEventCommand()
- {
- if (Event != null)
- Event.Dispose();
- }
- #endregion
- }
- }
|