ApplicationViewPrinting Event

Subscribe to the ViewPrinting event to be notified when Revit is just about to print a view of the document.

Namespace: Autodesk.Revit.ApplicationServices
Assembly: RevitAPI (in RevitAPI.dll) Version: 25.0.0.0 (25.0.0.0)
Syntax
public event EventHandler<ViewPrintingEventArgs> ViewPrinting

Value

EventHandlerViewPrintingEventArgs
Remarks

This event is raised when Revit is just about to print a view of the document. If multiple views are combined to a single file, this event will be raised only once.

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 not cancellable. The 'Cancellable' property of event's argument is always False.

The following API functions are not available for the current document during this event:

  • All overloads of Autodesk.Revit.DB.Document.Export()
  • Autodesk.Revit.DB.Document.Print()
  • Print and similar overloads.
  • SubmitPrint and similar overloads.
  • [!:Autodesk::Revit::DB::Document::Close()] and similar overloads.
  • [!:Autodesk::Revit::DB::Document::Save()] .
  • [!:Autodesk::Revit::DB::Document::SaveAs(String)] and similar overloads.

Exception InvalidOperationException will be thrown if any of the above methods is called during this event.

Another event ViewPrinted will be raised immediately after view printing is finished.

Example
public class Application_ViewPrinting : IExternalApplication
{
    /// <ExampleMethod>
    /// <summary>
    /// Implement the OnStartup method to register events when Revit starts.
    /// </summary>
    public Result OnStartup(UIControlledApplication application)
    {
        // Register related events
       application.ControlledApplication.ViewPrinting += new EventHandler<Autodesk.Revit.DB.Events.ViewPrintingEventArgs>(AppViewPrinting);
        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.ViewPrinting -= new EventHandler<Autodesk.Revit.DB.Events.ViewPrintingEventArgs>(AppViewPrinting);
        return Result.Succeeded;
    }
    /// <TrivialCode>
    /// Code ID: 501
    /// For ViewPrinting class description
    /// </TrivialCode>


    /// <summary>
    /// Handler method for ViewPrinting event, it will display some event arguments. 
    /// </summary>
    public void AppViewPrinting(object sender, Autodesk.Revit.DB.Events.ViewPrintingEventArgs args)
    {
        StringBuilder info = new StringBuilder();
        info.AppendLine("ViewPrintingEventArgs Parameters ------>");
        info.AppendLine("    Event Cancellable   : " + args.Cancellable);
        info.AppendLine("    TotalViews          : " + args.TotalViews);
        info.AppendLine("    View Index          : " + args.Index);
        info.AppendLine("    View Information    :"); // View
        DumpViewInfo(args.View, "      ", ref info);

        TaskDialog.Show("Revit",info.ToString());
    }

    /// <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 added to message box string.</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>
}
See Also