From the course: Revit: Creating C# Plugins

External applications

From the course: Revit: Creating C# Plugins

Start my 1-month free trial

External applications

- [Instructor] We've learned a lot about how to work with the Revit API during this course, and we've done this by creating external commands to execute our code in Revit. Now let's have a look at another way that we can create commands in Revit, that execute based on events or part of a custom user interface. These are known as external applications. Just like we had created a command that inherits from the IExternal command, we can also create plugins that implement the IExternalApplication interface or IExternalDBApplication interface. The IExternalApplication provides access to the Revit user interface, along with some events, through the Revit API. When implementing the IExternalApplication interface, it requires that we override two methods, the OnStartUp method and OnShutDown method, both of which take a UIControlledApplication object as the parameter. When a plugin is registered with an IExternalApplication, the OnStart method will be called when Revit starts up. Revit will then pass the UIControlledApplication object to the method. When Revit shuts down, the OnShutDown method will be called, with the same UIControlledApplication object being passed to the method. When these methods end, they return the result to Revit. Within our external application plugin, the UIControlledApplication object represents the user interface and provides access to user interface customization methods and events. We can add external commands to the user interface ribbon by utilizing methods such as CreateRibbonTab, CreateRibbonPanel, or AddStackedItems. We can also use it to access events such as a dialog box showing, a view activating, or when Revit's idling, to execute functions when the different events occur in the project. The external application is used to access application or user interface events. In order to access database-level events, we need to use an IExternalDBApplication interface. The IExternalDBApplication interface is similar to the IExternalApplication interface, except that it does not provide access to the user interface. They can be used to create add-ins that assign to events that aren't related to the UI and access the DB-level events as required. Just like the IExternalApplication, a class that inherits from the IExternalDBApplication interface needs to implement the OnStartUp and OnShutDown methods. These methods take a ControlledApplication object as the parameter. The return type for these methods is a different result in that it's accessed from an ExternalDBApplication class. The ControlledApplication object will be passed by Revit and provides access to database-level events, which includes document opening, document synchronizing with central, and document saving. All of these provide access to the document via the events arguments. When creating an IExternalApplication or IExternalDBApplication, we need to add in two different types to the manifest file from what we've been doing so far. As you can see, these look very similar to the external command types in the manifest. We still need to provide much of the same details, except for both of these types, they're going to be named differently. The first is the application type, this is used for the ExternalApplication, and the second is the DBApplication type, which is used for an ExternalDBApplication. Much of the same tags are used otherwise. So in this last section of the course, let's have a look at different ways that we can utilize these add-ins to further enhance our Revit plugins.

Contents