From the course: Revit: Creating C# Plugins
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Registering the event
We now have our event handler method. Next, we need to register the event so that it executes on the event notification, that is when the document changes via a transaction. So let's start by registering the event in the OnStartup Method. To do this, let's wrap it in a Try Except Statement in case an exception occurs when the event is registered. So let's remove the exception that is currently in our OnStartup method and add a try and catch. If there is an exception, let's simply return the result as failed. Keep in mind here that the external DB application has its own result enumeration separate from the external application result. So let's access ExternalDBApplicationResult.Failed. Now, let's subscribe to the event inside of the try block. To do that, let's access the document changed event via the controlled application object that is passed to the method using the application variable. Then, we can add a delegate to the event by using the += symbol. The delegate is a type that…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.