Getting Started with the Revit API

I am regularly forced to return to this topic, to provide a useful starting point for beginners.

The amount of available material is getting huge, and some help is required deciding where to start exploring the Revit API.

The most important thing to be aware of is the Revit Developer Center.

Start there by looking at the three DevTV video introductions and then work through the My First Revit Plug-in tutorial.

In these tutorials, you are shown how to locate, install and use the most basic development tools and information, including:

More detailed overviews of the available Getting Started material are provided for both Revit 2012 (still valid for 2013) and 2013. You should also take a look at the list of things to do to prepare for a hands-on Revit API training.

I suggest performing these steps:

Once you have completed these steps, you will be amply set up and ready to go, raring to get started properly on your own project.

Here is a list of typical questions you might run into:

How can I determine the relationship and dependency between elements?

Revit maintains a huge number of different relationships between database elements. How to determine these depends on the elements in question.

An extremely important tool to explore the relationships between elements in the Revit database is RevitLookup, included with the Revit SDK. Use of RevitLookup to explore the Revit database and relationships between elements is discussed and demonstrated in a large number of subsequent posts on The Building Coder blog.

An important technique to discover relationships that are not officially provided through the Revit API is demonstrated by the object relationship analyser (VB). Use of this technique is also discussed and demonstrated in many places.

Most relationships are accessible through much simpler official means, though.

As said, it depends on what elements you are talking about.

How can I integrate Revit data with an external database?

Please look at the following discussions:

How can I extract DWFX data from Revit?

Use the Document.Export method taking (String, String, ViewSet, DWFXExportOptions) arguments.

How can I modify the DWFX results?

You can export the DWFX. For any further modifications, you would have to take recourse to the DWF Toolkit.

How can I extract a thumbnail image for a specific element?

Look at the discussions on

How can I get a total count of properties, attributes and custom attributes for a given element?

You can easily achieve this, but there is no specific API call provided for this task. You have to implement it yourself, and the number will vary depending on your requirements, criteria, and implementation.

How can I compare the properties of two elements?

[Q] For instance, if two different objects have a property of the same name, can their values be compared or summarized together? E.g., a property of "Material" for a length of pipe might be copper; will a property of the same name on a copper elbow joint have the same "Material" value?

[A] I am pretty sure that a clever user can create a project in which this will not be the case.

When extracting data from Revit, what is the best approach to organize and retrieve that data?

That depends completely on your own needs. You will need to perform a careful analysis. Look at the database integration links listed above.

Is there a standard for all family element types (symbols) that remains the same from model to model?

No, unfortunately, the contrary is true. Families and types are completely user defined, and creating their definitions is just as much an art as a science.

Is there an easy way to list of all families and element types from a model?

Yes. To list all types, just filter for all ElementType objects:

  FilteredElementCollector a
    = new FilteredElementCollector( doc )
      .WhereElementIsElementType();
 
  foreach( Element e in a )
  {
    Debug.Print( "{0} {1} is an ElementType.",
      e.Name, e.Id.IntegerValue );
  }

To retrieve the families that they belong to, you can use the FamilySymbol.Family property.

And: I can promise you some surprises if you start exploring this :-)

What methods are there to "walk" all objects?

The filtered element collector is the only way to access in and retrieve elements from the Revit database, unless you have a unique id or an element id and can access the individual object directly.

Please look at the RevitLookup application, which is provided in source code as part of the Revit SDK.

First of all, it is an invaluable tool both for developers and even end users to interactively explore the database and relationships such as the ones you are asking about.

Secondly, it iterates the entire database and walks all the objects, so you can use that code directly.

Conclusion

I hope you find this useful.

In general, almost every single question that you run into in your initial steps of implementing a Revit add-in has already been asked and answered somewhere. Make good use of the help file, global search of the sample code, developer guide and then turn to an Internet query.

Believe me, it is easy and it is fun... both the development part and the research... it is all creative :-)

Good luck!

Project Tracking for Kids

Oh, and one last thing... also fun... where tracking is child's play... a few days late for April first :-)