This is not yet another getting started tutorial on Revit API, but rather a concise checklist and minimum development environment that one can test and verify the system is working before diving into more complex code.
0. the prerequisites:
Make sure Revit 2015/2016 and Visual Studio 2012/2013 is installed. Revit 2015 will not work with older Visual Studios.
1. the project:
Create a new “Class Library” project in “Visual C#” with “.NET Framework 4.5”.
2. the references:
Add RevitAPI.dll, RevitAPIUI.dll and System.Windows.Forms as project references.
Change the “Copy Local” property of RevitAPI.dll and RevitAPIUI.dll to false.
3. the class:
Inherit the Autodesk.Revit.UI.IExternalCommand interface.
Add the following class attribute code before the class declaration.
4. the method:
Implement the Execute method of the inherited interface.
public Autodesk.Revit.UI.Result Execute(
ref string message,
5. the assembly:
Press F6 and VS should report “Build succeeded”.
Note the output path of the dll file shown in the Output window.
6. the GUID:
Create a unique ID for your command.
7. the .addin file
Create an empty text file in: C:\Users\yourUserName\AppData\Roaming\Autodesk\Revit\Addins\201X
Change the file name to anyNameWillWork.addin.
Open the file and copy or type the following code:
<?xml version="1.0" encoding="utf-8"?>
Now start Revit and you should see an “Add-Ins” tab at the end of Revit tabs, in which there is an “External Tools” button with the newly created External Command.
9. (optional) the debugging:
Point the “Start external program” to the installed revit.exe.
Go to Tools – Options – Debugging, check “Use Managed Compatibility Mode”.
Set a break point in your code.
Press F5 in VS and Revit should be started.
Activate your plugin and you break point should be hit.
~~~~~~~~~~END of original post~~~~~~~~~~
A GitHub repository is created, with the complete Test project for Revit 2016 API. The only thing you need to do is edit the Assembly line in the .addin file, and copy the file to your Revit Addins folder. You are welcome to download the code, and let me know if there are any questions and problems. Enjoy!
As mentioned at the beginning of this post, the content in this post is as concise as possible. If you want more information, here is a tutorial from Autodesk Revit API documentation that contains more details. You may also find the other parts of the documentation to be useful when you try to dig dipper.