01 Days 08 Hrs

🥳 Late-Bird Launch Is Coming on Feb 29th!

🥳 Late-Bird Launch Is Coming on Feb 29th!

Create Your Own Custom pyRevit Extension

Creating custom extension in pyRevit is super easy! We just need a folder structure and pyRevit knows what to do next.

Create Your Own Custom pyRevit Extension

Creating custom extension in pyRevit is super easy! We just need a folder structure and pyRevit knows what to do next.

Summary

Create your own pyRevit Extension.

💛 I can't say enough how much I love pyRevit. And in this lesson will you understand one of the reasons.

📁 pyRevit gives us the easiest way to create an extension. All we have to do is - create a folder structure and place our python files. And to make it look nicer, we will also add icons.

That's how simple it is…

You can see example in the image 👉
The left column is the bare minimum we need.

Just make sure you use specific suffixes for your folder names. This way pyRevit will be able to read and understand the folder structure.

🔎 Let's explore all of them.

.Extension

First of all, we need .extension folder. This will tell pyRevit that we have an extension folder structure inside. Nothing fancy here.

📁 I will create a folder named: LearnRevitAPI.extension

💡You can use any name instead of LearnRevitAPI!

.Tab

Next we need to create .Tab folder. This will represent a tab visible in Revit UI. We can also create multiple tabs if you want to separate your tools better, but as a beginner: Keep it simple!

📁 I will create a folder named: LearnRevitAPI.tab

.panel

Next we need to create panels inside of our Tab. This helps us to organize our tools better. You can see in the screenshot above that I have panels for Sheets, Views, UI, Elements, Naming…

You can name your panels anything you want, just make sure you have the right suffix in the end - .panel

📁 I will create folders named:
Dev.panel
Resources.panel

.pushbutton

Finally, we need to create our actual buttons. There are a few different options for creating a button, but the most common one is .pushbutton

Inside of this file we will need a script file and optionally we can add an icon. And that's the bare minimum it takes to create an extension with a button for Revit.

❗We can name our scripts anything we want as long as script.py is in the end.
like: MagicButton_script.py

❗icon has to be named icon.png and can have max size 96x96 pixels.

💡pyRevit can also support .dyn | .cs | .vb | .gh. Refference pyRevit Bundles documentation to learn more.

📁 I will create the following folder:

FirstButton.pushbutton

Get Free Icons

You can get your icons from anywhere. Just make sure you name them icon.png and they don't exceed max size of 96x96px.

👉Personally I use icons8.com because it's simple to use.

.urlbutton

There are multiple types of buttons we can create in pyRevit, and you can learn more about them in pyRevit Bundles page in pyRevit Dev Docs(link below).

.urlbutton is another type which is great for storing paths and URLs to useful resources. I would recommend adding a few buttons with links to documentation and all valuable resource you are going to find on your programming journey. Keep your gems close!

To do that, we need to place bundle.yaml file instead of our script and then write correct meta tags inside. Here is simplest example to include Title, Description and the link itself.

title:   LearnRevitAPI Website
tooltip: Link for Coolest Revit API website.
hyperlink: "https://www.LearnRevitAPI.com"
pyRevit Custom Directory

If you followed along, you have enough to load a few of your buttons in Revit as an extension. We just need to let pyRevit know where your folder structure is located.

To do that:

Open Revit -> pyRevit Tab -> pyRevit Settings -> Custom Extension Dirs -> Add Folder

Then you just need to point to the folder where your .extension folder is located.

Do not select .extension folder itself. We need parent folder where it's located!

Example:
✔️ C:\Users\ef\AppData\Roaming\CustomRevitExtensions

✖️ C:\Users\ef\AppData\Roaming\CustomRevitExtensions\LearnRevitAPI.extension

Then you just need to point to the folder where your .extension folder is located.

Do not select .extension folder itself. We need parent folder where it's located!

Example:

✔️ C:\Users\ef\AppData\Roaming\CustomRevitExtensions

✖️ C:\Users\ef\AppData\Roaming\CustomRevitExtensions\LearnRevitAPI.extension

Then you just need to point to the folder where your .extension folder is located.

Do not select .extension folder itself. We need parent folder where it's located!

Example:

✔️ C:\Users\ef\AppData\Roaming\CustomRevitExtensions

✖️ C:\Users\ef\AppData\Roaming\CustomRevitExtensions\LearnRevitAPI.extension

Then Click on Save Settings and Reload, and you should find your very own Custom Extension in Revit tabs! Isn't it great?

Containers

By now you know how to create an extension with a few buttons. But they take quite a lot of space in the toolbar. So we need to be smart about how we organize them.

There are 2 main container-like bundles in pyRevit.

  • .stack - Create a stack of up to 3 buttons. You can include .pulldown bundles.

  • .pulldown - Create a collection of buttons with a pulldown menu.

📁 You just have to create these folders and then place .pushbutton or other button type folders inside of them, like you placed in .panel before.

You can see image examples below 👇

💡You can name your stacks anything, but I prefer to call them col1.stack, col2.stack…
This way they are ordered correctly based on their names.

💡Choose a name for pulldown folder same as you would want to see in Revit UI. For example in the image above I have an example of Rooms.pulldown.

pyRevit Dev Docs

Be sure to check our pyRevit Developer's Documentation.

It's really well written and has plenty of useful tutorials and examples. I didn't know that for a long time when I started and I regret that.
Don't make my mistakes and at the very least have a glance around what's available.

HomeWork

It's time for you to create your custom extension using pyRevit.

✅Create Folder Structure
✅Point its path in pyRevit
✅Reload pyRevit to see you extension

⌨️ Happy Coding!

Questions:

I can't see my extension in Revit tabs.