前言
这三个例子都是通过注册事件来完成相应的工作,内容比较简单。
内容
事件参考博客: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 自动更新
这个例子仅仅是更新了地址信息:文章来源:https://www.toymoban.com/news/detail-689642.html
- 注册文件打开完成事件
application.ControlledApplication.DocumentOpened - 事件处理函数
在文件上加入地址信息
doc.ProjectInformation.Address = “United States - Massachusetts - Waltham - 610 Lincoln St”;
CancelSave
这个例子也注册了一系列事件,但作用和题目出入太大,这个例子应该从 SDK Sample 中删除。文章来源地址https://www.toymoban.com/news/detail-689642.html
到了这里,关于Revit SDK 介绍:AutoStamp 自动水印 & AutoUpdate 自动更新 & CancelSave的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!