Resources
Summary
Welcome Back to REIT Hackers
Welcome back to REIT Hackers.
So you know how to select your elements with REIT API by now.
And now we're going to look inside these elements and figure out how to read some values out of them.
And to do all that, we'll use an amazing plugin called REIT Lookup, and it's free and it's a must-have for any REIT API developer.
It allows you to inspect your elements inside of Revit and see all Revit API properties and methods, and most importantly, the values that they return.
I can’t wait to show you how it works, but first of all, let's go and install it.
Installing Revit Lookup
So open your browser and search for Revit Lookup. You can also write “GitHub” if you want, but you are looking for this page right here by Jeremy Teek.
So I'm gonna click on that one. Inside of here, you wanna scroll down, and you'll notice right here on the right side there are gonna be releases.
So click on that one, and whatever is your latest version, I'm gonna click on 2025. Then scroll down until we can see right here assets.
And you'll notice there is 2021, 2022, 2023, 2024, 2025, and so on.
So in here, you can select the version that you need. So in my case, I need this one: 2025, and I'm gonna take the single-user license.
Now I'm gonna click on that one, and it's gonna install it. Then we're gonna run it as usual.
You might also see this message, “Windows protected your PC,” and in there, this is really safe to use it.
I'm gonna click on “More info” and “Run it anyway.”
Now before I'm gonna go through the installer, I just wanna quickly show you that this plugin was developed by Jeremy MiTek, who was a part of Autodesk team for many years, and he's very well known in the Revit API space.
So it's definitely safe to use it ‘cause it has the backing of Autodesk.
Now we're gonna click here, then you can see where it's installed if it matters to you. Click on “Next,” and we're gonna click on “Install.” It takes just literally a second, and it's ready.
And now, once it's installed, we can open Revit 2025 (or whatever version you use), and we're gonna have a look at how to work with this.
Using Revit Lookup
Now we can see, first of all, we're gonna see “Would you like to load it?” I’m always gonna load it, and now we are inside of Revit.
Alright, so I just opened the sample project from Autodesk, and now we need to select some elements. Let’s say that we wanna pick maybe this wall and maybe this, I dunno, door. That’s fine.
Then go to the “Add-Ins” tab right here, and you’ll notice there is this Revit Lookup button appeared. You can click on it, and there are different ways you can snoop.
The most used one is gonna be Snoop Selection and Snoop Active View. In my case, I have some selections, so I can snoop it.
And this is the thing: whenever you're gonna use it, you can look inside the elements. You can see here on the left your selected items. In my case, I selected this item and this one.
And right here on the top, you can see the class of these items. So the first one is the “family instance,” which means it’s a loadable family—probably it’s a lamp—and here it has a class of “Wall.”
Now right here on the right, you have all the properties and methods, and we have the name of the member—it’s gonna be either property or method—and then the value it returns.
Let’s just quickly scroll through and see, and see for example here, there is the ID of the selected element, the group ID.
And while you’re exploring it here, “-1” in Revit API means None. So in case there is supposed to be, like, element ID of the group, and if it doesn’t have any group, it’s gonna say “-1.”
Demolished phase is also “-1,” so it’s not demolished.
Now I can scroll through, and you’ll notice there are a lot of different information, and it might be really confusing in the beginning, but don’t worry; it’s very repetitive.
Firstly, I want you to know that, for example, right here on the top, it says “Element,” and these are all the properties and methods from the Element class. Then if I’m gonna scroll down, I’ll also notice “HostObject.” Then here are the properties and methods of the HostObject. And then here is the “Wall” class, and these are all the properties and methods of the Wall class.
‘Cause, you see, even though it’s a Wall class, the Wall class is based on the HostObject, and HostObject is based on the Element, and it kinda keeps all the properties and methods from the previous classes, and we can access all of them here.
Now let’s go to the Wall methods, and for example, you can see “IsFlipped” — it says “False.” “IsStackedWallMember” — it’s not. And for example, here is the “Width.”
Another thing is that all numeric values in Revit API, they’re gonna be in feet. So if you work in metric system like I do, you would also need to convert it. But I’m gonna show you in a moment.
And these are pretty much the properties, and we could, for example, if we would want to get the width, we would kinda get our wall, and then we would just write here “Width,” ‘cause this is a property.
If that’s a method—let’s for example, I dunno, there is method “GetTypeId.” This one is good. This one is a method. First of all, if it’s an action like “get” or some kind of checks, usually it’s a method. But you can also kinda verify everything inside of Revit API documentation. Over time, you will get familiar with this because it’s very repetitive.
Let me just open Revit API documentation. I’m gonna just choose this here, and I’m gonna write “GetTypeId.” I’m gonna take the first one. And you can see this is a method, doesn’t take any arguments, and you can also learn how to use it. You can also see it comes from “Element” class, and that’s fine. This is from where it was inherited.
And in here, what you will notice also, that you have just regular text—for example, “Name” is gonna be this, “OwnerView” is this, “Pinned” is false. Also in here, you have your bold orange text, and if it’s orange bold text, it means you can open and look further, ‘cause look here: the “GetTypeId” is gonna return you a type of this element. And if I’m gonna click on it, now I’m gonna open a menu for the Wall type of this element. Now I can keep looking inside, I can look, oh, there is a category, and I’m gonna get a category of walls. And then you will notice there’s also “Material.” You really can go deeper and deeper inside this kind of hierarchy of elements and how they’re connected.
And I’m gonna show you later how it all works. But first, let’s read some values. So for example, we are gonna go, and with the code, we’re gonna try to read “ElementId.” We are gonna read maybe “LevelId,” if it’s possible, and maybe we are also gonna read the type. These are gonna be a really good exercise. So I’m gonna leave this on the screen.
And now here, I’m gonna click on the “Power Hacker,” and we’re gonna use the second button right here. So let’s hold ALT and click on it, and we’re just gonna repurpose this button.
So let me open the script, and here it is. There is some code from previous lessons; we don’t need it. And let’s clean up the description. This is gonna be tutorial on how to read properties and methods with Revit API. Alright, now let’s rename it. It’s gonna be “Look Inside Elements,” and I don’t really need the dates. I’m gonna remove this.
Okay, the imports, we don’t need any of that. We might keep just the first one. And now, first of all, we actually need to pick some object in Revit. Now for that, we’re gonna use the “PickObject” method, and you already know how it works. We’re gonna write “Reference of picked object” equals “uidoc.Selection.PickObject.”
(Below is a smaller snippet referencing how to pick an element, just as we do in the script.)
We are gonna convert it into an element. We’re gonna do it by doc.GetElement(reference_of_picked_object).
Alright, I think that should be fine. Let’s first of all make a print statement, and it’s gonna be the type of the element just to see what is the class of the selected element.
Now let’s go back, and I’m gonna click here on Button 2, and let’s pick the same wall. You can see it’s a “type of Wall.” So now we’re gonna look inside and read some values. Maybe I’m gonna make it side by side so it’s a little bit easier for you to kinda follow through.
Okay, a thing like this should be enough. Let’s have a look. So first of all, we’re gonna write here that we are picking an element. Let’s add here some emoji. And now we’re gonna read properties. So we don’t need this print statement anymore.
Let’s have a look. I’m gonna write “print(element.Id),” and you notice this property “Id” also says right here. And this is the value that we are gonna get when we are gonna print it. But also, this is not integer, this is “ElementId,” and you can test it, but you will get used to that.
Then let’s also say that I wanna read my “LevelId,” and I know that this is a property, so I’m gonna try it: come here, “LevelId.” Then, since it’s a “LevelId,” I can also get an actual element. Let’s say that “level” is gonna be “doc.GetElement(element.LevelId).” Now we’re gonna print a level. You’ll notice in Revit API everything is usually referenced as “ElementId” because it’s kind of saving the memory inside and making it quicker. So you’ll often have to convert it into actual elements.
And then the third one, we also gonna try to use this—where is it—this one: GetTypeId().
Now let’s just duplicate one of the lines. I’m gonna write “GetTypeId.”
(Below is a smaller snippet referencing how to read properties, just as we do in the script.)
Alright, so here are the first few print statements, and let’s go and test it. I’m gonna leave this menu; it will be necessary later, and I’m gonna pick this wall. Alright, and here I return values. Let’s put it here on the side. I’m gonna open the code so I can explain it.
So, first of all, we are making this element “Id,” and you can see it’s giving us an “ElementId” right here. This is the second one, and it’s also giving us the number. Then we are actually getting an element from this element “Id,” and it’s gonna be a level. I can see in here it returns you “Autodesk.Revit.DB.Level.” And lastly, we try to get GetTypeId()
, but you’ll notice in here it tells you “built-in method,” so you know that this is not a property, this is a method, and therefore it did not return you the value. And when it’s a method, it means that you have to use parentheses like this.
And sometimes there are arguments, sometimes there are not. In this case, there are no arguments. But if there would be, you would get an error saying it takes 1, 2, 5 — how many arguments it needs. Then you can go to Revit API documentation and explore why it doesn’t work.
Now let me just try it one more time. We’re gonna get a different main statement. This time you’ll notice it’s also gonna be an ElementId right here. Now I don’t like that I’m getting this number, so let’s go and change it a little. “ElementId” is fine, but we wanna print it like this. We wanna make a string “Element Id:” then we can write a format. If I would have two of the things here, I could write “text A” and then “text B.” And when you do “format” like this, the first one is gonna go here, and the second one is gonna go here.
So we can write here, for example, “ElementId,” then “LevelId,” then “LevelName.” Now for the “LevelId,” you already know we need to take that part. And for the level name, we need to get “level” and then we need to read its name. Let’s just find our level, and then in level, you can also explore all its properties, and you’ll notice here is the name. The thing is that about inheritance—you’ll notice that nearly all your elements are gonna be inherited on Element. So all these properties are gonna be available pretty much to all your elements. All your elements are gonna have “Category,” all of them gonna have “Document,” “Id,” “GroupId,” “Location,” “Name,” and so on, so on, so on. In the beginning, that’s a bit overwhelming, but over time, you’ll get used to this—that all of them have a name, Id, and all these properties.
Now we can remove all of that. And then we are getting here a type, which is gonna be element.GetTypeId().
This is actually “typeId,” and to get a type, it’s gonna be doc.GetElement(typeId).
One really important thing is that you should never use the word “type” inside of Python, because this is actually a built-in kinda function, and when you do it like this, you override it, and it can lead to all sorts of error. Instead of that, we’re gonna call it “elementType” or anything else, but not “type,” and we’re gonna leave the “type” function as it is.
And there is also a little bug, and you will see the error message in a second. But whenever you try to read “Name” from your “FamilySymbols” and “Types,” you’re gonna get an error saying that you cannot read “Name” property. It is there, it just does not see it. I dunno why. There’s this workaround that you would have to remember in case you cannot read the “Name” property. So for the type, I’m gonna make it here: elementTypeName = Element.Name.GetValue(elementType)
. And this is not the standard way—it’s like internal way to use it—but it works. That’s all that matters.
So we’re gonna put it here, let’s try it again. Click on Button 2, Wall. Now I can read all these properties, and these are very simple properties to read, and you can already get a lot of information out of it. You can make your “if” statements and test: does it have this kind of wall type? Then do this, and so on.
Reading Materials (Advanced)
Alright, now I wanna make it a little bit more interesting. Let’s just close all of that, and I’m gonna select the wall, and let’s go to “Edit Type.” And then let’s say that we wanna explore the materials. So normally, what you do is you select your wall, you open your type, then you go into the structure, and inside the structure, you’ll find all these layers right here. And then you could go in into each layer and have a look, for example, at the material, at the thickness, maybe some other properties, and then you can make your decisions based on that.
Also, I am in the imperial system right now, so I’m gonna change it to metric because I have no idea how much it is. So let’s just quickly change to “Manage,” find “Project Units.” I’m gonna set the length to metric. I have no idea how much feet, and in metric, I’m gonna set it maybe to centimeters. It should be fine. Yeah.
And now we’re gonna repeat the same steps but inside the Revit Lookup. So we’re gonna go to “Add-Ins.” We already selected the wall. We’re gonna click here, and I’m gonna snoop selection. Now usually, you follow the same steps: we have our wall, and secondly, we need to find the wall type. I’m gonna use this GetTypeId()
which is here. This is gonna give you the type of this wall. Now in here, we needed to look for something like “structure.” So let’s scroll through.
And normally, when you’re getting the specific elements, you first of all can go all the way down to “WallType” or “HostObjectType,” ‘cause this is not kinda not “Element” property or method, but this is something else. Here, you can see that we can get something right here. There is “GetCompoundStructure,” and it sounds exactly what we need. So let’s click on that one. Inside of here, again, you have a bunch of different properties and methods, and I can already see right here “GetLayers.” So that’s what I need. Also, another tip: if you know that you’re looking for the list of items or for reference to another element, just look for the bold orange colors. This means that you can keep exploring inside of them. So let’s click on that: “GetLayers,” and inside there, here are all our layers. Obviously, it’s a list of layers, and you will also notice that right here on the right, you have your “MaterialId,” and you have your “Width,” and that’s pretty much what we wanted.
So let’s go now and replicate all the steps inside of code. I’m gonna open the code right here, and we’re gonna write here, “Second step is read materials,” and we’re gonna add “advanced” ‘cause we are really reading a lot.
First of all, we need our type, and I’m just gonna copy it right here. So we already went from the wall. We already have the type. Now we want to get “CompoundStructure.” So I’m gonna write here structure = elementType.GetCompoundStructure().
Again, sometimes you need some arguments, sometimes you don’t. You can just always try and see what you get. Don’t be afraid of getting errors; they’re just kinda like a warning: “Hey, you forgot to do something.”
Alright, so we got our structure. If I spelled it correctly, now inside of it, let’s click on here. We’re gonna go, and we are interested in getting the layers. So I wanna write layers = structure.GetLayers().
Let’s click on that one. And it’s gonna be a list of items. So we can also just print all of these things. Maybe we’re gonna print structure, and we’re gonna print layers. And since it’s a list of items, I already know that I can iterate through it. So I’m gonna write, “for layer in layers,” and we’re gonna print layer. Let’s just quickly test this thing before we continue. This is gonna make it a little bit more clear maybe.
So we’re gonna click on the button, gonna select the wall, and we’re gonna get a lot of different print statements and an error. It says something is not defined, and I think I misspelled something somewhere. And yeah, this is because in here, it’s supposed to be “layers.” Now it’s gonna work. Let’s try it again. I’m gonna do this, and here we go. These are our first print statements. Then here we’re getting compound structure, then we’re getting a list of compound structure layers, then there is this list until here, I think, and then we are printing each layer individually, one by one. So now we can have a look inside these layers.
Let’s just quickly come here, “Add-Ins,” “Revit Lookup,” “Snoop Selection.” Again, we are inside of instance, so we want to get our type, gonna be this “GetTypeId,” then we wanna get something with the structure, just this “GetCompoundStructure,” and then there was something with layers: “GetLayers.” Now we can iterate through all these items, and we’re gonna read “MaterialId” and “Width.” Let’s quickly do that. So we’re gonna write:
Now for each layer, we can do:
(Below is the smaller snippet that ties it all together for reading materials in the script.)
Let’s put it here on the top. And we’re gonna get “material name” by looking at “mat.Name.” Lastly, we just gonna print it. Now we can run it, and in this case, that’s all good. “Here’s material info: metal panels blah blah blah,” “4.445 centimeters, oh, this matching feet, then air,” and so on. In this case, there are no errors. Everything works. But I also want you to always think like a programmer: you don’t always get all your values. Let’s say I’m gonna add a new material here, and I’m not gonna select material; I’m gonna leave it by category.
So I’m gonna click on OK, actually the thickness, that’s okay. I’m just gonna move this material down, and I’m gonna wait a little. It probably will mess up my project a little, but that’s okay. I’m gonna ignore all the warnings, and I’m just gonna say, “Okay, do whatever.” Now I’m gonna run it again, and I’m gonna click here, and you’ll notice, whoa, there is an error. And this is a very common one. When you read here, “NoneType object has no attribute ‘Name’ / ‘Width’ / ‘MaterialId’” or whatever, it means that you did not get your element before reading some property. It’s on line 62. Let’s go have a look. We’re gonna come here, and line 62 is here. So we’re trying to read the “Name” property, but we did not get any material because sometimes you might have that there is no material. And this is exactly what happened right here.
So this one is “None,” and therefore we cannot get “Name.” So we can just check here: “if mat: then we do that, else we’re gonna write mat_name = 'None'.” Again, let’s quickly try it before I’m gonna show you what’s happening. We’re gonna click on it, and now I can see it works. It’s right here, “None” or “No material.” Maybe “No material” is better, but now how it works. So whenever you write your code, always think about how can you break it right away if you select an element, what happens if you don’t select or if there is no value here or there, and so on.
Alright, and I wanna congratulate you because we’ve just learned your second concept about Revit API on how to look inside your elements and how to read its properties and methods. And now I want you to practice it: pick some elements in Revit and try to read different properties and methods and see how much information can you already get out of your elements, and try different categories as well.
This step is already great for getting a lot of information out of your elements. However, the majority of information in Revit is stored in parameters, and that’s the next concept that we’ll look into in the next lesson. I wanna wish you happy coding, and I’m gonna see you very soon in the next lesson!
HomeWork
…
⌨️ Happy Coding!