© 2010 Autodesk
Introduction to Revit 2011 API
Events
Event Handler, Registering and Unregistering events
§EventHandler
§
§
§
§Registering events
§
§
§
§Unregistering events
§
§
§
public Result OnStartup(UIControlledApplication application)
 {
            application.ControlledApplication.DocumentChanged += UILabs_DocumentChanged;
             return Result.Succeeded;
 }
public Result OnShutdown(UIControlledApplication application)
{
            application.ControlledApplication.DocumentChanged -= UILabs_DocumentChanged;       
            return Result.Succeeded;
}
public void UILabs_DocumentChanged(object sender, DocumentChangedEventArgs args)
{
// Do something here
           
}
First, you must have a function that will handle the event notification. This function must take two parameters, the first is an Object that denotes the ―sender of the event notification, the second is an event-specific object that contains event arguments specific to that event. For example, to register the DocumentSavingAs event, your event handler must take a second parameter that is a DocumentSavingAsEventArgs object.

The second part of using an event is registering the event with Revit. This can be done as early as in the OnStartup() function through the ControlledApplication parameter, or at any time after Revit starts up through external commands.