1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- using Autodesk.Revit.UI;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace FWindSoft.Revit
- {
- /// <summary>
- /// 处理者,就是接收者
- /// </summary>
- public class RevitHandler : IExternalEventHandler
- {
- public RevitHandler() : this(Guid.NewGuid().ToString("N"))
- {
- }
- public RevitHandler(string name)
- {
- this.Name = name;
- }
- public RevitHandler(string name, Action<RevitEventArgs> action) : this(name)
- {
- if (action != null)
- {
- Executing += (s, e) => action(e);
- }
- }
- public RevitHandler(Action<RevitEventArgs> action) : this(Guid.NewGuid().ToString("N"), action)
- {
- }
- #region 接口逻辑实现
- public void Execute(UIApplication app)
- {
- this.UIApp = app;
- var args = new RevitEventArgs();
- args.UIApp = this.UIApp;
- args.Handler = this;
- OnPreExecute(args);
- if (args.Handled)
- return;
- OnExecute(args);
- if (args.Handled)
- return;
- OnPostExecute(args);
- }
- /// <summary>
- /// 命令名称
- /// </summary>
- public string Name { get; protected set; }
- public string GetName()
- {
- return Name;
- }
- #endregion
- /// <summary>
- /// 关联UIApp
- /// </summary>
- public UIApplication UIApp { get; private set; }
- #region 事件处理相关
- public event EventHandler<RevitEventArgs> PreExecute;
- public event EventHandler<RevitEventArgs> Executing;
- public event EventHandler<RevitEventArgs> PostExecute;
- public virtual void OnExecute(RevitEventArgs args)
- {
- if (Executing != null)
- {
- Executing(this, args);
- }
- }
- protected virtual void OnPreExecute(RevitEventArgs args)
- {
- if (PreExecute != null)
- {
- PreExecute(this, args);
- }
- }
- protected virtual void OnPostExecute(RevitEventArgs args)
- {
- if (PostExecute != null)
- {
- PostExecute(this, args);
- }
- }
- #endregion
- /// <summary>
- /// 关联参数
- /// </summary>
- public object Parameter { get; set; }
- }
- }
|