0% found this document useful (0 votes)
132 views2 pages

External Command in 10 Steps For Revit 2015

This document provides a 10 step checklist for setting up and running an external command in Revit 2015/2016 API. The steps include: 1) Creating a class library project in Visual Studio and adding Revit API references; 2) Inheriting the IExternalCommand interface and implementing the Execute method; 3) Building and getting the DLL path; 4) Creating a unique command ID; 5) Creating an ADDIN file pointing to the DLL; 6) Now the external command will be available in Revit's AddIns tab. Optional steps include debugging the external command in Visual Studio. The document also provides a link to a GitHub repository with a sample project and the Revit API documentation.

Uploaded by

Jignesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
132 views2 pages

External Command in 10 Steps For Revit 2015

This document provides a 10 step checklist for setting up and running an external command in Revit 2015/2016 API. The steps include: 1) Creating a class library project in Visual Studio and adding Revit API references; 2) Inheriting the IExternalCommand interface and implementing the Execute method; 3) Building and getting the DLL path; 4) Creating a unique command ID; 5) Creating an ADDIN file pointing to the DLL; 6) Now the external command will be available in Revit's AddIns tab. Optional steps include debugging the external command in Visual Studio. The document also provides a link to a GitHub repository with a sample project and the Revit API documentation.

Uploaded by

Jignesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

EXTERNAL COMMAND IN 10 STEPS FOR REVIT 2015/2016 API

2014/04/29 LE ZHANG 3 COMMENTS

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.

[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.

7. the .addin file


Create an empty text file in: C:\Users\yourUserName\AppData\Roaming\Autodesk\Revit\Addins\201X
(or C:\ProgramData\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"?>
<RevitAddIns>
<AddIn Type="Command">
<Assembly>C:\yourAddinPath\youAddinName.dll</Assembly>
<AddInId>yourLong-Long-Long-Long-GuidGoesHere</AddInId>
<FullClassName>yourAddinNamespace.YourAddinClassName</FullClassName>
<Text>ExternalCommandTest</Text>
<VendorId>LZNT</VendorId>
</AddIn>
</RevitAddIns>
8. DONE!
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~~~~~~~~~~

~~~~~~~~~~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

You might also like