8 Tips to Get Started with Revit API and Python
Aug 27, 2024
This post is an excerpt from an upcoming course with Erik Frits, founder of LearnRevitAPI. You will learn all the steps to build your own custom toolbar using Python & pyRevit.
📅 Release Date: Available now!
🕖 Duration: 1h48
Revit often requires repetitive, tedious tasks. Instead of manually performing these tasks, using automation tools such as plugins can help you save time and focus on what really matters.
While plugins are great, they have their limits. For specific, custom tasks, it's hard to find the exact tool you are looking for.
That's when custom automation comes into play.
Dynamo is a great gateway to playing the Revit API (Automated Progamming Interface). But you can go a step further and integrate your own toolbar in the Revit ribbon, and have a truly custom and powerful tool easy to access by your teammates.
C# is the language used to develop Revit plugins that you can install with a .exe file. But learning C# is complex.
That's when Python comes into play. Here are the reasons why it's a better pick than C#:
Overall, both languages have their place and time in Revit. But for beginners wanting to quickly develop a toolbar, Python is probably the best pick.
The good news is that Revit API skills are transferable from Python to C#.
Python is known for being beginner-friendly. As Jean-Marc Couffin says, "Python is basically English."
You don’t need to be a Python expert to use the Revit API, but understanding the basics is important.
There are tons of great resources out there, such as this course by the MIT.
Familiarize yourself with key programming concepts like:
To develop your own toolbar, these three Revit tools are essential:
Visual Studio Code, a desktop app by Microsoft, is a must-have. When properly configured, it can autocomplete Revit tools and commands in your code, helping you manage multiple apps within your toolbar.
It also colors and displays the code in a way that is easier to read and understand.
What is so great about pyRevit is how quickly you can create a custom toolbar extension.
You only need to set up a folder structure with subfolders for each tool, containing the code (.py file) and an icon (.png file).
You can create pushbuttons, stacks, pulldowns, and more using specific naming conventions for your folders.
Now, you need to develop your code. pyRevit and the extensions are open-source, which means you can access the tools made by others, and maybe even reuse the code.
Here is a trick: ALT-click on a pyRevit tool, and it will open the folder where the script is located, revealing the .py file.
A great way to learn is to explore the code made by others.
To be clear: the point of stealing like an artist is to learn and improve. This doesn't mean you should steal the code of others and pretend you made it.
Revit API is huge. You cannot know all the classes.
That's why you should use this great free resource website: Revit API docs by Gui Talarico.
Inside the docs, you can choose a Revit version, search for specific classes, and browse categories.
The code snippets are in C#, but you can use ChatGPT to translate them into Python. With time, you’ll be able to do it yourself.
The best way to use ChatGPT is to think of it as a buddy sitting next to you who has deep knowledge about Revit API, Python, and programming.
You can ask questions about code, translate code from C# to Python, and help you understand and learn the Python language. In a way, it's a bit like having a private tutor.
And yes, you can ask to write part of your code.
With that said, a strong foundation in Python, Revit API, and programming is still a crucial step in combining all the ingredients.
We have collaborated with Erik Frits of LearnRevitAPI to create a short course called Develop a Custom Revit Toolbar. It goes through all the steps to get started with the Revit API and create your own tools.
🕖 Duration: 1h48
Enter your details below to get this free guide.