前言
这个例子展示的是 Revit 进度通知的能力,在打开文件的过程中,Revit 会有相应的事件通知。
内容
这个例子的关键入口在 MainWindow 里注册两个事件,m_application.ProgressChanged
和 m_application.DocumentOpened
:
// Revit 2021 SDK\Samples\Events\ProgressNotifier\CS\MainWindow.xaml.cs
public MainWindow(Autodesk.Revit.ApplicationServices.Application application)
{
InitializeComponent();
m_application = application;
m_progressStack = new ProgressStack();
m_application.ProgressChanged += new EventHandler<Autodesk.Revit.DB.Events.ProgressChangedEventArgs>(RevitApp_ProgressChanged);
m_application.DocumentOpened += new EventHandler<Autodesk.Revit.DB.Events.DocumentOpenedEventArgs>(RevitApp_DocumentOpened);
m_cancel = false;
m_receivedCancelEvent = false;
m_previousEvent = null;
}
ProgressChanged
ProgressChanged
的事件可能的通知类型:
namespace Autodesk.Revit.DB.Events
{
public enum RevitAPIEventStatus
{
// 失败
Failed = -1,
// 成功
Succeeded = 0,
// 取消
Cancelled = 1
}
}
对应的事件处理函数相对来说也很简单:
void RevitApp_DocumentOpened(object sender, Autodesk.Revit.DB.Events.DocumentOpenedEventArgs e)
{
textBox_log.Text += "RevitApp_DocumentOpened: Cancellable:" + e.Cancellable.ToString() + " , IsCancelled: " + e.IsCancelled().ToString() + " , Status:" + e.Status.ToString() + Environment.NewLine;
m_receivedCancelEvent = (e.Status == Autodesk.Revit.DB.Events.RevitAPIEventStatus.Cancelled);
}
ProgressChanged
ProgressChanged
对应的状态:
对应的处理函数:
总结
Revit 的这些事件暴露了一些自己内部处理的流程,给了用户一定的自由度去做自己的事情。在进行文件批处理的时候有一定的作用,当然也可以尝试在这个过程中进行一些加密和解密的操作。