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
Why use the Revit API?
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.
1- Python vs C#: what's the difference?
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#:
- It is easier and faster to learn than C#.
- It is more readable code (easier to understand).
- Python has huge libraries of snippets for Revit API.
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#.
2- Understand the basics of Python and programming
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:
- Data types
- Operators
- For loops
- Conditional statement (if, then, else)
- Functions
- Error handling
3- Install these 3 plugins: pyRevit, Revit Python Shell and Revit Lookup
To develop your own toolbar, these three Revit tools are essential:
- pyRevit: Known for its amazing Revit tools, this free open-source plugin also lets you develop your own extension using Python. Download here
- Revit Python Shell: This plugin allows you to run Python scripts directly in Revit. Download here
- Revit Lookup: Revit elements have hidden properties beyond what’s visible in the parameters. Revit Lookup lets you access and play with these properties in the API. Download here
4- Install a code editor (Visual Studio Code)
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.
5- Quickly generate a pyRevit extension
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.
6- Steal like an artist
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.
7- Use Revit API Docs
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.
8- ChatGPT is your friend
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.
Get the course: Develop a Custom Revit Toolbar with Erik Frits
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