From the course: Revit: Creating C# Plugins

Classifying elements

From the course: Revit: Creating C# Plugins

Start my 1-month free trial

Classifying elements

- [Instructor] When working with a Revit model we tend to build up everything from different objects such as walls, furniture, floors, and windows. All of these objects in Revit derive from a base class in the Revit API known as the element class. Therefore a Revit project is essentially a collection of different elements. In order for us to search through and find the different elements we are working with, we need to understand some of the different ways that they can be classified. Four of these different ways are by their category, family, symbol, or instance. In the Revit API elements have a property which stores the category that it belongs to and this is used to identify what the element type is. Categories therefore describes a group of similar elements in which the element type is associated. For example all of the walls will belong to the walls category and all the doors to the door category. Every BuiltInCategory in Revit, that is a default category will have an associated BuiltInCategory enumeration. So the wall category can be retrieved by its BuiltInCategory which we'll look at in more detail in the coming videos. Elements can also be classified by the family they belong to, families are the element classes that are grouped together in the different categories, and they usually are grouped by their common use, parameters, and appearance. In the Revit API there are two types of families. System families, and component families. System families tend to be built in, such as walls. Component families tend to be constructed externally and brought into the project such as furniture. Elements can therefore be identified by the family that they belong to, a family is then represented by a set of different family symbols, or family types, each with their own set of settings. For example, we might have a basic wall family in our project which many different family symbols derive from, in Revit we tend to call these family types and we use these family types to create different types of a family. Therefore in the API we can retrieve elements by their family type or family symbol. A family instance then is simply a constructed object in the Revit model of a particular family symbol, or family type, accessing the different element categories and element types allows us to differentiate between different elements in the project file. Especially when filtering for and accessing different elements. So let's jump back into Visual Studio, and look at retrieving an element from its element ID, and then later we can retrieve all of its details. In this earlier exercise, we retrieved the element ID of a selected element, now let's have a look at retrieving the actual element. We can do this using the GetElement method from the project document, let's have a look at that in the Object Browser, by going to the Object Browser tab. If you don't have this open, you can get to it by double clicking the Revit API reference and then searching GetElement, as you can see at the top there are three over-loaded GetElement methods. Meaning they are all the same, but each take a different parameter. We can either provide an element ID, reference or string which is the unique identifier for an element. Another property which can be used to identify elements. As we retrieve the element from the Revit as a reference document, we could use this to get the element object. Let's use the GetElement method that takes an element ID so we can look at this task that we'll have to perform quite frequently in the API. All we need to do first is get the document, as the GetElement method is accessed from this object. Currently on line 18, we assigned the active UI doc from the application, we can use this to also retrieve the document by accessing the document property on the UIDocument object. So let's create a Document variable, named doc and we'll assign to this the current document using uidoc.Document, great we can now retrieve the element from the document using the element ID and the GetElement method we just looked at. After we have picked the object, let's create an element ID variable named eleId, and then as we did in the previous video we can retrieve the element ID property from the reference object we have stored in the obj variable. Now using this element ID we can retrieve the picked object as an element, to do this let's create an element variable named ele and we'll assign to this the element by accessing the GetElement method from the document stored under doc, and for the parameter let's add eleId. Great, so now that we have learned how to retrieve an element using the element ID, let's have a look at extracting all the information from the element.

Contents