Application: PrintLog
Revit Platform: All
Revit Version: 2011.0
First Released For: 2010.0
Programming Language: C#
Skill Level: Medium
Category: Basics
Type: ExternalApplication

Subject: Dump print information to log.
Summary: 
This sample demonstrates how to subscribe Print related events, access properties in argument of event handlers and dump print related information to log file.

Classes: 
Autodesk.Revit.UI.IExternalApplication 
Autodesk.Revit.UI.IExternalCommand 
Autodesk.Revit.DB.Events.ViewPrintingEventArgs
Autodesk.Revit.DB.Events.ViewPrintedEventArgs
Autodesk.Revit.DB.Events.DocumentPrintingEventArgs
Autodesk.Revit.DB.Events.DocumentPrintedEventArgs

System.DateTime
System.Diagnostics.Stopwatch

Project Files: 
Application.cs
This file contains a class Application which implements IExternalApplcation interface. The OnStartUp method will register ViewPrinting, ViewPrinted, DocumentPrinting and DocumentPrinted events when Revit starts.

Command.cs
This file contains a class Command which implements IExternalCommmand interface. The function of the class is to call API Document.Print to raise ViewPrint and DocumentPrint related events.

EventsReactor.cs
This file contains a class EventsReactor, it has four handler methods which will be subscribed to ViewPrint and DocumentPrint events separately; it also contains other methods which are used to dump related information to log files.

This class will dump all print information (printer name, project name, start and end time of each print process, individual print time of each view and total print time for all views, events related information) to PrintLog.txt; besides, it also dumps events related information to PrintEventsLog.txt file.

EventsWatches.cs
This file contains a class EventsWatches which has two stop watches used to calculate time consumed for View printing and Document printing.

Description: 
The sample implements IExternalApplication interface and subscribes ViewPrinting, ViewPrinted, DocumentPrinting and DocumentPrinted events in OnStartUp; the registered event handlers will dump print related information to log files.
-	Event handlers of ControlledApplication.ViewPrinting, ViewPrinted, DocumentPrinting and DocumentPrinted will be subscribed to react to the print actions.
-	ViewPrintingEventArgs properties Cancellable, View, Index and TotalViews will be dumped to log when view is about to be printed.
-	ViewPrintedEventArgs properties Status, Cancellable, View, Index and TotalViews will be dumped to log when view has been printed.
-	DocumentPrintingEventArgs properties Cancellable and Views will be dumped to log file when document is about to be printed. 
-	DocumentPrintingEventArgs properties Status, Cancellable PrintedViews and FailedView will be dumped to log file when document has been printed.
-	System.DateTime and System.Diagnostics.Stopwatch will be used to dump start (when ViewPrinting or DocumentPrinting is raised) and end time(when ViewPrinted or DocumentPrinted is raised) of print events and calculate the individual print time for each view and total print time for all views.
-	API Document.Print(ViewSet) can raise ViewPrint and DocumentPrint related events to verify  functionalities of this sample.

Instructions: 
1.	Copy the provided .addin file under sample folder to install folder of your Revit and specify full paths for dll. 
2.	Start Revit, notice that ViewPrint and DocumentPrint events will be registered once Revit starts.
3.	Raise print events by API: Run external command to call API to raise prints events. And then refer to log files PrintLog.txt for more details about print information dumped by this sample.
4.	Raise events by UI: Run UI print command File\Print to print views and then refer to PrintLog.txt.