Wednesday, October 17, 2012

Start Revit API Programming - First Plug-in

After having an introduction on programming with C#, from today we officially start working on Revit API programming. Meanwhile, I will try to add more posts on programming with C# and provide you with some useful links.

In order to start Revit API programming you need to have the following software installed:
  1. Autodesk Revit 2013 - You can download the student version of this software here.
  2. Microsoft Visual Studio 2010 - How to Download Microsoft Visual Studio Free for Students Post illustrates the steps to download visual studio 2010 free for students. If you are not a student, you can download C# express instead here.
  3. Revit 2013 SDK - You can download Revit 2013 SDK from Autodesk Developer Network (ADN) . You can find more detail on how to install Revit 2013 SDK later in this post.

The best place to start learning on API programming is ADN website. After opening this page, first watch the video under My First Plug-in Title. This video gives you some ideas about how a plug-in works and what you can do with a very simple revit plug-in.

Then scroll down to the bottom of the page and download the Revit 2013 SDK from Tools. Then run the file you have downloaded and install the Revit 2013 SDK. This software adds a new tab to your Revit interface named Add-Inns. You will use this tab to run the plug-ins that you create later. Also,It will creates a folder with the same name in you Local Disk (C:). Go to this folder and browse all the files and folders in it.You can see what folders and files should be in your SDK folder in the following image.

Between these files and folders you will use the following more than others:
  1. Add-In Manager - Go to this folder and run the executive file named Add-In Manager for Autodesk Revit 2013. this program gives you an interface to manage your plug-ins. It will help you a lot and make your work much easier. We will come back to this topic later.
  2.  Samples - This folder contains a huge amount of API samples that you can go through and learn more about API programming. I would recommend you to find a sample close to what you want to do and use it as base for your projects.  In the samples folder, there are some .html files. These files help you to get more information on samples such as their difficulty.
 Let's go back to ADN website and create the first plug-in. Read the overview and then go to lesson 1: The Basic Plug-in. In this lesson you will create your very first basic Autodesk Revit plug-in for copying groups selected by the user to a specified location. Follow all the steps other than 7,8, and 9 from Steps To Create First Plug-in. You do not need to do these steps, since Revit 2013 can interact with .NET Framework 4.  Also, Do not do the Writing an AddIn Manifest. You will use add-in manager that you have installed in the previous step instead.

There are some changes in the Running the Plug-in too. When you go to Revit, in the Add-Ins tab in the external tools you will have Add-In managers tool as shown in the following.


Choose the Add-In Manager (Manual Mode). A new window will pop up. Select the load botton on this window and locate your dll file.

When you load the .dll file, you will see your class and .dll file in the Loaded Commands tab  of this window.

Select the class name and hit Run button. Then follow step 4 and 5 of the Running the Plug-In of the ADN website.

Then read Lesson 2 and Lesson 3 to learn more about API programming. 

No comments:

Post a Comment