My First Plug-in Training

My First Revit Plug-in Overview

Are you an Autodesk Revit power user with an interest in becoming even more productive? Would you like to automate or extend the capabilities of Revit, but are new to computer programming? If so, then this guide is designed for you.

“My First Plug-in” is a self-paced tutorial guide for a smooth introduction into the programming world. This is a “one-stop shop” learning path for users who know Autodesk products but are absolutely new to programming and are thinking about taking the plunge. In this guide, you will be working with Autodesk Revit .NET API and the C# programming language, however if you prefer the programming language VB.NET we have provided the code samples in this language as well.

Product: Autodesk Revit*
Programming Language: C# (and VB.NET - does not include written explanations for VB.NET code samples)
Application Programming Interface (API): Revit .NET API

*This guide was created based on Autodesk Revit Architecture. All steps in this guide are applicable to any product of the Revit three flavors. You can replace all “Revit Architecture” with “Revit Structure” or “Revit MEP” in this guide with version 2011 or higher. For version 2011 and 2012 we provide instructions to work with Visual Studio Tools for Applications (VSTA) inside the archive lesson download, VSTA has been replaced in Revit 2013 with SharpDevelop.

Overview

There are many resources available on the web for you to learn about the Autodesk Revit API (Application Programming Interface), however, these resources tend to be designed for people who already know programming. This guide is different: it assumes no previous programming knowledge and yet helps you build your first plug-in quickly, without swamping you with details. You’ll have a working application within an hour of starting this material, irrespective of your current level of programming expertise.

The guide will start by reviewing the benefits of customizing Autodesk software before progressing onto lessons covering the use of the Autodesk Revit API. The lessons will start by building a working plug-in before covering more detailed explanations of the underlying principles and further developing the application’s functionality.

The Benefits of Customizing Autodesk Revit

In today’s world, you’re encouraged to become more and more efficient. This is a key benefit of customization: tailoring the software you use on a daily basis to streamline workflows increases your efficiency. Autodesk provides powerful APIs and SDKs (Software Development Kits) that allow you to gain greater value from your investment in Autodesk software by tailoring it specifically to the needs of your business.

Autodesk Revit provides a rich API that can be used to customize the product’s existing features or by adding entirely new ones. You can automate repetitive, time-consuming tasks and extend core features without leaving the Autodesk Revit environment. The API can be used to create custom tools and features that plug directly into Autodesk Revit, extending its functionality.

Autodesk Revit has a .NET API which means you can use any of the .NET compliant programming languages (C#, VB.NET, F#, etc.) to develop a plug-in. While each language has its own relative benefits, C# is the natural choice for this guide: it is easy-to-learn, easy-to-use and leverages the power of the underlying .NET Framework. As you become comfortable with the content of this guide - and more proficient with C# - you’ll be able to move on to solving more complex problems with the language.

Despite C# being the natural choice, sometimes there are limitations outside your control of what languages you can work with within your company. The programming language VB.NET takes a very close second place to C#, so to accommodate readers looking to work with VB.NET in Autodesk Revit; we have provided you all the lesson code in VB.NET.

Programming can be very rewarding. We hope you feel that way too after completing these lessons. Have fun!

Summary of the Plug-in

“My First Plug-in” implements a command to copy a group (can contain furniture, partition walls or Mechanical Electrical Plumbing (MEP) elements) from one room to another.

It’s very common for building models to contain identical furniture layouts, and copying these elements manually can prove both time-consuming and tedious: it can be quite challenging to have elements maintain the same relative position, for instance. This type of task is ideally suited for automation via the Autodesk Revit API, and this guide will take you through the process of doing just that.

Video: The Completed Plug-in
This video demonstrates the final plug-in you will be creating in Lesson 6 of this “My First Plug-in” guide. 

Software to Install Prior to Starting

  • Autodesk® Revit® Architecture 
    This guide is applicable for Autodesk Revit Architecture 2011 and succeeding versions. Please replace the '20xx' to the product version that you are using throughout the guide.
  • Microsoft® Visual C# Express
    This material focuses on the steps needed to use Microsoft Visual C# 2010 Express. Using other versions of Visual Studio that support C# is also possible.

Video: How to Install Visual C# 2010 Express

Summary of the Lessons
  • 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.
  • Lesson 2: Programming Overview
    In this lesson, you will look more closely at what happens when you execute the plug-in code, exploring the Visual C# Express environment.
  • Lesson 3: A First Look at Code
    In this lesson, you will take your first in-depth look at the Autodesk Revit API. We’ll spend time looking at the C# code you typed into your plug-in in lesson 1, understanding each of the lines of code in turn. Additionally, exploring such concepts as Object-Oriented Programming, classes, methods, variable declarations, creating class objects and properties.
  • Lesson 4: Debugging your code
    Learn how to use the Visual Studio debugger to step through your code line-by-line to follow the program execution; and to watch the values of variables as they are changed by your code.
  • Lesson 5: Simple Selection of a Group
    In this lesson, you will improve the plug-ins selection functionality, by making it easier for the user to select a group and make sure your plug-in anticipates the possibility of something unexpected happening.
  • Lesson 6: Working with Room Geometry
    In this lesson, you will extend the plug-in to copy the selected group to a location relative to the center of the room it is in. Additionally, exploring such Revit API and programming concepts as Filtering with FilteredElementCollector and the conditional if statement.
  • Lesson 7: My Final Plug-in
    In this lesson, you’ll complete the plug-in’s functionality by extending it to allow the user to select multiple rooms to which the group will be copied to.
  • Lesson 8: Learning More
    In this lesson, we provide you with additional information to increase your productivity when creating Autodesk Revit plug-ins. You will look at information on API-related help, documentation, samples and where to go next to continue your learning around the Autodesk Revit API.