这个例子介绍了如何使用打印相关的事件。
事件机制也是老生常谈了,Revit 提供了大量的可供注册的事件:Revit API:Events 事件总览
注册和 print 相关的事件:
// IExternalApplication.OnStartup
m_eventsReactor = new EventsReactor();
application.ControlledApplication.ViewPrinting += new EventHandler<Autodesk.Revit.DB.Events.ViewPrintingEventArgs>(m_eventsReactor.AppViewPrinting);
application.ControlledApplication.ViewPrinted += new EventHandler<Autodesk.Revit.DB.Events.ViewPrintedEventArgs>(m_eventsReactor.AppViewPrinted);
application.ControlledApplication.DocumentPrinting += new EventHandler<Autodesk.Revit.DB.Events.DocumentPrintingEventArgs>(m_eventsReactor.AppDocumentPrinting);
application.ControlledApplication.DocumentPrinted += new EventHandler<Autodesk.Revit.DB.Events.DocumentPrintedEventArgs>(m_eventsReactor.AppDocumentPrinted);
在 AppDocumentPrinting
中启动记录,在 AppDocumentPrinted
中输出执行时间。
在 AppViewPrinting
中启动记录,在 AppViewPrinted
中输出执行时间。
底层时间戳用了 .Net 的类 Stopwatch:
namespace System.Diagnostics
{
public class Stopwatch
{
public static readonly long Frequency;
public static readonly bool IsHighResolution;
public Stopwatch();
public bool IsRunning { get; }
public TimeSpan Elapsed { get; }
public long ElapsedMilliseconds { get; }
public long ElapsedTicks { get; }
public static long GetTimestamp();
public static Stopwatch StartNew();
public void Reset();
public void Restart();
public void Start();
public void Stop();
}
}