前言
这三个例子都是通过注册事件来完成相应的工作,内容比较简单。
内容
事件参考博客:Revit API:Events 事件总览
AutoStamp 自动水印
使用到的事件:
application.ControlledApplication.ViewPrinting
application.ControlledApplication.ViewPrinted
注册事件:
public class Application : IExternalApplication{
EventsReactor m_eventsReactor;
public Autodesk.Revit.UI.Result OnStartup(UIControlledApplication application){
// Register related events
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);
return Autodesk.Revit.UI.Result.Succeeded;
}
public Autodesk.Revit.UI.Result OnShutdown(UIControlledApplication application){
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);
return Autodesk.Revit.UI.Result.Succeeded;
}
}
事件处理:
// AppViewPrinting
TextNoteOptions options = new TextNoteOptions();
options.HorizontalAlignment = HorizontalTextAlignment.Center;
options.TypeId = e.Document.GetDefaultElementTypeId(ElementTypeGroup.TextNoteType);
TextNote newTextNote = TextNote.Create(e.Document, e.View.Id, XYZ.Zero, strText, options);
// AppViewPrinted
e.Document.Delete(m_newTextNoteId);
AutoUpdate 自动更新
这个例子仅仅是更新了地址信息:
- 注册文件打开完成事件
application.ControlledApplication.DocumentOpened - 事件处理函数
在文件上加入地址信息
doc.ProjectInformation.Address = “United States - Massachusetts - Waltham - 610 Lincoln St”;
CancelSave
这个例子也注册了一系列事件,但作用和题目出入太大,这个例子应该从 SDK Sample 中删除。