Application: ApplicationEvents
Revit product and version: All
Last Modified: 29/01/2007
Modified By: JY Autodesk HSL
Programming Language: C#

Subject:  This sample demonstrates how to subscribe to Application Events and how to create custom menus.

Classes: 
Autodesk.Revit.IExternalCommand
Autodesk.Revit.IExternalApplication
Autodesk.Revit.Events.ApplicationEvents
Autodesk.Revit.MenuItem
Autodesk.Revit.Application
Autodesk.Revit.Document

Project Files: 
Command.cs
This file contains the class Command which inherits from IExternalCommand interface and implements the Execute method.

ExternalApplication.cs
This file contains one class TopLevelMenu which inherits from IExternalApplication interface and implements OnStartup and OnShutdown methods. In OnStartup method a custom menu named "Track Revit Application Events" is created to correspond to the Command class in Command.cs file.

RevitApplicationEvents.cs
This file contains one class RevitApplicationEvents which inherits from ApplicationEvents interface and implements all the events handler methods. And in this class OnDocumentClosed, OnDocumentOpened, OnDocumentSaved and OnDocumentSavedAs events of Revit Application object are subscribed.

InformationWindows.cs
This file contains a form class ApplicationEventsInfoWindows which consists of one DataGridView to show user the Revit Application object events history log. The event log item includes the event happening time, the user who operates the Revit, the event type and the document which is operated.

Description: 
The sample creates one custom top level menu and one sub-menu when Revit application starts up and uses this sub menu to show or hide a modeless window which displays the Revit application object events’ history log.
-	This sample will subscribe to Application’s document open, close, save and save as events.
-	This sample lists document’s opened, closed, saved or saved as information in a modeless window when the document is opened, closed, saved or saved as.
-	This sample creates a custom top level menu named “MyCustomTopMenu”. And below this top menu a menu named “Track Revit Application Events” is created too to show and hide the modeless window.
Implementations:
-	The class which answers for adding custom menus must implement IExternalApplication interface. And the custom menus should be created in OnStartup method.
-	Application.CreateTopMenu method and MenuItem.Append method can be used to create custom menu.
-	OnDocumentOpened, OnDocumentClosed,OnDocumentSaved and OnDocumentSavedAs event handlers of Application class can be used to subscribe to relevant events.

Instructions: 
1.	Make sure there are following settings in Revit.ini file 
[ExternalApplications]
EACount            = 1
EAClassName1 = Revit.SDK.Samples.ApplicationEvents.CS.TopLevelMenu
EAAssembly1    = (your path)\ApplicationEvents.dll
2.	Run Revit, then you can see a custom top menu “MyCustomTopMenu” with a sub-menu named “Track Revit Application Events” in Revit. 
3.	Click “Track Revit Application Events” menu an events history log window will appear.
4.	Close the Revit document, then a new document closed event log item will appear in the events history log window’s DataGridView. When open, save, SaveAs document will generate relevant events log.
5.	Click “Track Revit Application Events” menu again, the events history log window will disappear. 
6.	After window disappears, click “Track Revit Application Events” menu once more, the window will appear again.