Revit + Python

Why Python, and How Do I Get Started?

W

Once you’ve decided that it’s worth your time to learn about and create your own Revit tools, your first question is probably ‘Why Python’?  It turns out that there are a few very good reasons to use this programming language to create your own personal tools.

  • Python is a relatively easy language to learn:  Compared to some other programming languages, Python is straight-forward and somewhat more intuitive.  According to python.org, “Python’s simple, easy to learn syntax emphasizes readability and therefore reduces the cost of program maintenance. Python supports modules and packages, which encourages program modularity and code reuse.”  Revit API commands aside, it’s not too difficult to look at a Python script and understand what each line of code is doing.
  • When using RevitPythonShell, it’s incredibly simple to copy code into the interface and run it.  This allows for very quick testing of scripts, with immediate feedback on successes and errors.
  • pyRevit is what really makes Python coding worthwhile in Revit.  Created by Ehsan Iran-Nejad (see here), pyRevit allows users to make their own custom Revit toolbars that are updateable on the fly.  Once it’s installed, there’s no need to force users to update their add-ons or wait for corrections to code to be pushed out.  Because pyRevit looks directly at the Python scripts, as soon as a coder updates the script, all users are automatically running the updated version.  Along with the other advantages of Python, this always-up-to-date functionality makes it easy to have custom office toolbars deployed on any number of computers.
  • Finally, there’s no need to compile Python code in order for it to run.  This allows for very rapid testing and deployment of scripts, and revisions to scripts don’t require lost time waiting for the program to compile.  While Python may not be as powerful as some other languages, this lack of complexity makes it perfect for the part-time coder.

In order to run Python scripts within the Revit Environment, either RevitPythonShell or pyRevit needs to be installed on the local machine.  

To install RevitPythonShell, go to the link, scroll down, and select the installer for the appropriate version of Revit you are running.  Once downloaded, run the .exe and follow the prompts. Installation will require admin rights to your local machine.  Once installed, the RevitPythonShell button will appear in the Add-Ins ribbon within Revit.

For pyRevit, go to the link and download the latest _signed.exe file.  Once downloaded, run the .exe and follow the on-screen prompts.  Installation will most likely require admin rights on your local computer.  pyRevit will install a new Revit ribbon called, surprisingly, pyRevit. There are a number of very useful tools already included with this addin.

I highly recommend reading through the websites for both RevitPythonShell and pyRevit to understand how both of those tools are expected to be used.  While I may cover some instructions here and there, I won’t be creating any tutorials on how to actually use these addins – the creators of them already pretty clearly explain how to use their creations.

For the most part, I’m going to focus on writing scripts to be used in tandem with pyRevit from here on out.  pyRevit allows for permanent tools within Revit, which should be the ultimate goal. While good for testing, RevitPythonShell is mainly meant for one-off scripts and doesn’t serve long-term productivity tools.

What do you think?  Is Python a relatively easy language to learn (in comparison to other programming languages)?  Are there other Python addins for Revit that are as effective as (or more effective than) pyRevit and RevitPythonShell?  How do you create your own addins for Revit?

About the author

Andrew Urban

With almost 15 years as a registered architect, and nearly as much experience using Revit, I have recently taught myself Python and have begun to create productivity increasing addons for Revit. I'm am always interested in learning new and innovative ways to use Revit and all other tools of our profession.

By Andrew Urban
Revit + Python

Andrew Urban

With almost 15 years as a registered architect, and nearly as much experience using Revit, I have recently taught myself Python and have begun to create productivity increasing addons for Revit. I'm am always interested in learning new and innovative ways to use Revit and all other tools of our profession.