External Command in 10 Steps For Revit 2015
External Command in 10 Steps For Revit 2015
External Command in 10 Steps For Revit 2015
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.
3. the class:
Inherit the Autodesk.Revit.UI.IExternalCommand interface.
Add the following class attribute code before the class declaration.
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Automatic)]
4. the method:
Implement the Execute method of the inherited interface.
public Autodesk.Revit.UI.Result Execute(
Autodesk.Revit.UI.ExternalCommandData commandData,
ref string message,
Autodesk.Revit.DB.ElementSet elements)
{
System.Windows.Forms.MessageBox.Show("Hello World");
return Autodesk.Revit.UI.Result.Succeeded;
}
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.
~~~~~~~~~~Update 2015.5.15~~~~~~~~~~
GitHub:
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!
https://github.com/lezhangnet/RevitAPI
Reference:
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.
http://help.autodesk.com/view/RVT/2016/ENU/?guid=GUID-8EB25D2A-3CAF-486A-BA8E-C2BEF3DB68F6