In the Walkthrough: Hello World section you learn how to create an add-in application and invoke it in Revit. You also learn to create a .addin manifest file to register the add-in application as an external tool. Another way to invoke the add-in application in Revit is through a custom ribbon panel.
Create a New Project
Complete the following steps to create a new project:
- Create a C# project in Visual Studio using the Class Library template.
- Type AddPanel as the project name.
- Add references to the RevitAPI.dll and RevitAPIUI.dll using the directions in the previous walkthrough, Walkthrough: Hello World.
- Add the PresentationCore reference:
- In the , right-click to display a menu.
- From the menu, click . The dialog box appears.
- In the dialog box, click the Tab.
- From the list, select .
- Click to close the dialog box. PresentationCore appears in the Solution Explorer reference tree.
Figure 8: Add Reference
- Add the WindowsBase reference following similar steps as above.
Change the Class Name
To change the class name, complete the following steps:
- In the window, right-click to display a menu.
- From the menu, select and change the class' name to CsAddPanel.
- In the , right-click the Class1.cs file to display a context.
- From the CsAddPanel.cs. menu, select and change the file's name to
- Double click to open it for editing.
The Add Panel project is different from Hello World because it is automatically invoked when Revit runs. Use the IExternalApplication interface for this project. The IExternalApplication interface contains two abstract methods, OnStartup() and OnShutdown(). For more information about IExternalApplication, refer to Add-in Integration.
Add the following code for the ribbon panel:
Code Region 2-5: Adding a ribbon panel
public class CsAddpanel : Autodesk.Revit.UI.IExternalApplication
public Autodesk.Revit.UI.Result OnStartup(UIControlledApplication application)
// add new ribbon panel
RibbonPanel ribbonPanel = application.CreateRibbonPanel("NewRibbonPanel");
//Create a push button in the ribbon panel "NewRibbonPanel"
//the add-in application "HelloWorld" will be triggered when button is pushed
PushButton pushButton = ribbonPanel.AddItem(new PushButtonData("HelloWorld",
"HelloWorld", @"D:\HelloWorld.dll", "HelloWorld.CsHelloWorld")) as PushButton;
// Set the large image shown on button
Uri uriImage = new Uri(@"D:\Sample\HelloWorld\bin\Debug\39-Globe_32x32.png");
BitmapImage largeImage = new BitmapImage(uriImage);
pushButton.LargeImage = largeImage;
public Result OnShutdown(UIControlledApplication application)
Build the Application
After completing the code, build the application. From the menu, click . Output from the build appears in the Output window indicating that the project compiled without errors. AddPanel.dll is located in the project output directory.
Create the .addin manifest file
To invoke the application in Revit, create a manifest file to register it into Revit.
- Create a new text file using Notepad.
- Add the following text to the file:
Code Region 2-6: Creating a .addin file for an external application
<?xml version="1.0" encoding="utf-8" standalone="no"?>
- Save the file as HelloWorldRibbon.addin and put it in the following location:
- For Windows XP - C:\Documents and Settings\All Users\Application Data\Autodesk\Revit\Addins\2012\
- For Vista/Windows 7 - C:\ProgramData\Autodesk\Revit\Addins\2012\
Note The AddPanel.dll file is in the default file folder in a new folder called Debug (D:\Sample\HelloWorld\bin\Debug\AddPanel.dll). Use the file path to evaluate Assembly.
Refer to Add-in Integration for more information about .addin manifest files.
To begin debugging, build the project, and run Revit. A new ribbon panel appears on the tab named NewRibbonPanel and Hello World appears as the only button on the panel, with a large globe image.
Figure 9: Add a new ribbon panel to Revit
Click to run the application and display the following dialog box.
Figure 10: Hello World dialog box