ApplicationDocument |
This event is raised when Revit is just about to print a view or ViewSet of the document.
Handlers of this event are permitted to make modifications to any document (including the active document), except for documents that are currently in read-only mode.
Event is cancellable. To cancel it, call the 'Cancel()' method of event's argument to True. Your application is responsible for providing feedback to the user about the reason for the cancellation.
The following API functions are not available for current document during this event:
Exception InvalidOperationException will be thrown if any of the above methods is called during this event.
After this event, for each view being printed, ViewPrinting and ViewPrinted events will be raised. Another event [!:Autodesk::Revit::DB::Document::DocumentPrinted] will be raised immediately after document printing is finished.
public class Application_DocumentPrinting : IExternalApplication { /// <ExampleMethod> /// <summary> /// Implement the OnStartup method to register events when Revit starts. /// </summary> public Result OnStartup(UIControlledApplication application) { // Register related events application.ControlledApplication.DocumentPrinting += new EventHandler<Autodesk.Revit.DB.Events.DocumentPrintingEventArgs>(AppDocumentPrinting); return Result.Succeeded; } /// <summary> /// Implement this method to unregister the subscribed events when Revit exits. /// </summary> public Result OnShutdown(UIControlledApplication application) { // unregister events application.ControlledApplication.DocumentPrinting -= new EventHandler<Autodesk.Revit.DB.Events.DocumentPrintingEventArgs>(AppDocumentPrinting); return Result.Succeeded; } /// <TrivialCode> /// Code ID: 501 /// For DocumentPrinting class description /// </TrivialCode> /// <summary> /// Handler method for DocumentPrinting event, it will display some event arguments. /// </summary> public void AppDocumentPrinting(object sender, Autodesk.Revit.DB.Events.DocumentPrintingEventArgs args) { StringBuilder info = new StringBuilder(); info.AppendLine("DocumentPrintingEventArgs Parameters ------>"); info.AppendLine(" Event Cancellable : " + args.Cancellable); info.AppendLine(" Views to be printed : "); // Views Application app = sender as Application; DumpViewsInfo(app, args.GetViewElementIds(), " ", ref info); TaskDialog.Show("Revit",info.ToString()); } /// <summary> /// Dump information of views: ViewType, Id and ViewName. /// </summary> /// <param name="views">Views to be displayed in message box.</param> /// <param name="prefix">Prefix mark for each line added to message box.</param> /// <param name="info">String where data is stored for display</param> private static void DumpViewsInfo(Application app, System.Collections.Generic.IList<ElementId> viewIds, String prefix, ref StringBuilder info) { int index = 0; UIApplication uiApp = new UIApplication(app); foreach (ElementId curViewId in viewIds) { Autodesk.Revit.DB.View curView = uiApp.ActiveUIDocument.Document.GetElement(curViewId) as Autodesk.Revit.DB.View; DumpViewInfo(curView, String.Format("{0}#{1}", prefix, index++), ref info); } } /// <summary> /// Dump information of single view: ViewType, Id and ViewName. /// </summary> /// <param name="view">View element to be displayed in message box.</param> /// <param name="prefix">Prefix mark for each line sent to message box.</param> /// <param name="info">String where data is stored for display</param> private static void DumpViewInfo(Autodesk.Revit.DB.View view, String prefix, ref StringBuilder info) { info.AppendLine(String.Format("{0} Id: {1}, ViewName: {2}, ViewType: {3}", prefix, view.Id.ToString(), view.Name, view.ViewType)); } /// </ExampleMethod> }