ViewPrinted Event


Subscribe to the ViewPrinted event to be notified immediately after Revit has finished printing a view of the document.

Namespace: Autodesk.Revit.ApplicationServices
Assembly: RevitAPI (in RevitAPI.dll) Version: 17.0.0.0 (17.0.1090.0)
Since: 2010

Syntax

C#
public event EventHandler<ViewPrintedEventArgs> ViewPrinted
Visual Basic
Public Event ViewPrinted As EventHandler(Of ViewPrintedEventArgs)
Visual C++
public:
 event EventHandler<ViewPrintedEventArgs^>^ ViewPrinted {
	void add (EventHandler<ViewPrintedEventArgs^>^ value);
	void remove (EventHandler<ViewPrintedEventArgs^>^ value);
}

Remarks

This event is raised immediately after Revit has finished printing a view of the document. If multiple views are combined to a single file, this event will be raised only once. It is raised even when view printing failed.

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.

Check the 'Status' field in event's argument to see whether the action was successful or not.

This event is not cancellable, for the process of view printing has already been finished.

If the action was not successful, the document may not be modified and new transactions may not be started.

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

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

Examples

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

    /// <summary>
    /// Handler method for ViewPrinting event, it will dump some event arguments. 
    /// </summary>
    public void AppViewPrinted(object sender, Autodesk.Revit.DB.Events.ViewPrintedEventArgs args)
    {
        StringBuilder info = new StringBuilder();
        info.AppendLine("ViewPrintedEventArgs Parameters ------>");
        info.AppendLine("    Event Status        : " + args.Status);
        info.AppendLine("    TotalViews          : " + args.TotalViews);
        info.AppendLine("    View Index          : " + args.Index);
        info.AppendLine("    View Information    :");
        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.IntegerValue, view.ViewName, view.ViewType));
    }
    /// </ExampleMethod>
}
Copy VB.NET
Public Class Application_ViewPrinted
    Implements IExternalApplication
    ' <ExampleMethod>
    ' <summary>
    ' Implement the OnStartup method to register events when Revit starts.
    ' </summary>
    Public Function OnStartup(application As UIControlledApplication) As Autodesk.Revit.UI.Result Implements IExternalApplication.OnStartup
        ' Register related events
        AddHandler application.ControlledApplication.ViewPrinted, AddressOf AppViewPrinted
        Return Result.Succeeded
    End Function

    ' <summary>
    ' Implement this method to unregister the subscribed events when Revit exits.
    ' </summary>
    Public Function OnShutdown(application As UIControlledApplication) As Autodesk.Revit.UI.Result Implements IExternalApplication.OnShutdown
        ' unregister events
        RemoveHandler application.ControlledApplication.ViewPrinted, AddressOf AppViewPrinted
        Return Result.Succeeded
    End Function
    ' <TrivialCode>
    ' Code ID: 501
    ' For ViewPrinted class description
    ' </TrivialCode>


    ' <summary>
    ' Handler method for ViewPrinting event, it will dump some event arguments. 
    ' </summary>
    Public Sub AppViewPrinted(sender As Object, args As Autodesk.Revit.DB.Events.ViewPrintedEventArgs)
        Dim info As New StringBuilder()
        info.AppendLine("ViewPrintedEventArgs Parameters ------>")
        info.AppendLine("    Event Status        : " & Convert.ToString(args.Status))
        info.AppendLine("    TotalViews          : " & Convert.ToString(args.TotalViews))
        info.AppendLine("    View Index          : " & Convert.ToString(args.Index))
        info.AppendLine("    View Information    :")
        DumpViewInfo(args.View, "      ", info)

        TaskDialog.Show("Revit", info.ToString())
    End Sub

    ' <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 Shared Sub DumpViewInfo(view As Autodesk.Revit.DB.View, prefix As [String], ByRef info As StringBuilder)
        info.AppendLine([String].Format("{0} Id: {1}, ViewName: {2}, ViewType: {3}", prefix, view.Id.IntegerValue, view.ViewName, view.ViewType))
    End Sub
    ' </ExampleMethod>
End Class

See Also