PyRevit first tutorial- Part 1

After AutoCad, that had LISP, where you could write some simple code and get some useful tailored tools that helped your efficiency, I find Revit tailoring a lot more difficult. It is more sophisticated and so programatically there are more challenges, so the code needs to be a bit more complex, but some simple Keyboard Shortcuts to change colours/linetypes to your personal pre-sets would be handy. I personally like Keyboard shortcuts as I don’t have to move the mouse from its location in the model space to get something from a pulldown menu.


I’ve used the PyRevit Add-in for a while, the Pattern app I found really good on a project i was working on, I used it for a tile layout and loved it.

I’ve made a couple of attempts to go through Ehsan Iran-Nejad’s PyRevit tutorials but was a bit blown away by them, only getting as far as t2nd tutorial. This time I perservered and also didn’t skip through them as I normally do. I am really impressed with the thought that has gone into this tool and just how adaptable it is. I highly recomment you watch the videos in the order that he has created them. He has a bit of a halting style but if you listen to what he is saying (I couldn’t grasp some of the issues the first couple of times I watched the videos) You’ll be richly rewarded with a comprehensive overview of both the Python, Revit, Revit API and coding methods that , this time around for me, make such a lot of sense.

Here is link to the tutorial playlist.

Maybe this time around I can actually do something that I want to do, as far as coding goes.


First off, C#. I did try and do some C# programming and did a few MicroSoft Courses on the subject. At the end of a lot of experimenting I only got one bit of code to partially run, so not a great success. Due to the lack of success I sort of stopped doing it. I also paid/downloaded a book and tried to follow on with that tutorial.

You need to compile the code, create a .DLL and then load that somewhere where Revit can find it before you can Test/Run it. A bit of a tedious method when testing a bit of code.


Python I have used successfully for a 360 Panorama setup, and once that process was developed it worked very smoothly. I’ve done a few tutorials with Python and go to monthly Python meetups in Wellington. They do some cool stuff in Python and its pretty versatile.

So using Python as an interface is something I’m more comfortable with. But it does distance you from the Revit API as that is based on C#, C++ or VB, so all Microsoft oriented programmes. So there is a bit of an interface issue in that all the API doc info is written around using C#, C++ or VB.

On the positive side, you don’t need to compile it, like you do with C# for Revit API. So you can alter the code , use the Interactive Python Shell Add-in to Revit:

And just test the code. As Ehsan say’s this is more of a test environment, where you can develop the code to do something, and if you wanted to make a commercial application then you can always re-write it in C# to compile. That being said, this is the level of access that I want ot use to test out ideas, and you can do it so quickly and responsively.

PyRevit first tutorial: Getting all Wall Volume from Model

So I followed his tutorial above, and it all ran fine apart from I couldn’t get the:

print(“Total wall volume is:()”.format(total_vol)) code all in one line working, so broke it down to 2 lines and it worked fine:

print(“Total wall volume is:”)

I must admit, most of the stuff in Python I’ve been doing has been in 3.4, so going back to 2.7 I know there are a couple of minor differences, one of them being print, so I may need to go and check on those.


I then followed the next video on how to adding Python tools, both a tab and button to tab bar. This is so cool. Your own code in your own tab, so you can just go and hit the button.

The other thing you can do is assign a Keyboard Shortcut to your button, so you can quickly access the tool via keys. This is such a handy way to test out your code.

Seeing other code by using ALT+ LeftMouseClick on button

A real issue I have is continuity. I follow the basic tutorial then flounder trying to do anything else. So its really helpful to be able to look at others code and see how they solved a problem, or a similar issue. This gives me a way forward to try and find a method for my solution. Its usually a hack, but it allows me to run something. If its useful I can always refine it later, if not, I just move on to something else.

So you can load some samples that others have, if they are useful, the hold Alt + Left mouse and open the location of that code and look at it, and experiment with it too. I think you need to put some sort of acknowlegement in of where you have got that information and acknowledging the creator of the code.

The beauty of PyRevit extensions & code- Copying/adding to your own toolbar

So there is the PyRevit tab, and there are other extensions that you can find on Github, and there are a lot of examples of solutions that people have developed to meet some process in Revit. You can copy usdeful bits of their code and put them on your Ribbon Add-in so that you can use their tools, or adapt them to your own purpose. So there is a lot of generosity out there of people working in this environment.

So this allows you to use the tools and practice with them to get familiar with them and understand how they have got to that solution.

Revit API documentation

In the tutorial video Ehsan points out a whole load of resources that he uses. The wbsite for the Revit API’s is a great one, RevitApiDocs

DataBases & Transactions

Ehsan is a genius, I love his explanation of databases. I was familiar with CRUD but not ACID (although I’ve seen references to it), so the video below makes so much sense.

Follwoing on from the Database explanation of the video above to then talk about Transactions in the video below is such a great lead-in to the subject, and I can understand the process and why it is used now.

So my next goal is to be able to use it properly. Thank you Ehsan.

End comment

A really amazing resource and lots of code that I can look at and hopefully learn from such that I can create some tools in Revit that I can use.

I’m still trying to think of a colour selection tool, but that needs a bit of research. Maybe some simple Keyboard Shortcuts to some pre-sets woyuld be a good stepping stone.

I really liked what Anton Bondarchuk has created with PyRevit.