pyRevit-03

/

/

/

pyrevit/03-personalize-extension

Personalize Your pyRevit Extension

You've just created your own pyRevit Extension, but it still looks like the template I've provided. So it's time to make some changes and make it more personal to you.

pyRevit-03

/

/

/

pyrevit/03-personalize-extension

Personalize Your pyRevit Extension

You've just created your own pyRevit Extension, but it still looks like the template I've provided. So it's time to make some changes and make it more personal to you.

Lesson Objectives

  • How To Customize Extension with Folder Structure

  • Use bundle.yaml for Visibility + Sorting

  • How-To Remove/Add Buttons and Panels

Are you Ready?

Summary

Personalize Your Extension

By now you should have your own Revit toolbar that looks like this:

And now I want to show you how to customize it to your own needs. It's 100% customizable so you can remove or add anything you want and it's as simple as copying or deleting a folder.

There are also a few tricks you should know about sorting and why new buttons might not show up, so let me explain you everything you need to know.

pyRevit Folder Structure

As I've mentioned in the previous lesson: pyRevit extensions are based on a very simple folder structure, and therefore we can change a few folders and it will update how our extension looks like.

The best way to understand how it work is to compare what you see inside of the folder structure and what you see inside of Revit. This will help you understand how to modify it to your own needs.

Open .extension folder we created previously (or use [ALT] + [CLICK] shortcut to open source folder of pushbuttons in Revit). Then we can explore what's going on inside

For example:

If you look inside of 📁…/YourName.tab /PlaceholderPanel.panel, you will notice a few folders that represent pushbuttons, stack of buttons or pulldown menu. These folders represent buttons inside your pyRevit extension.

You can also look inside .stack and .pulldown folders and you will find more pushbuttons.

For example here is what you will see inside of the PulldownExample.pulldown folder.

There are 3 pushbutton folders and each represents a button inside of Revit UI in your pulldown menu.

Same with StackExample.stack.

You will see pushbuttons and pulldown that relate to buttons inside of Revit UI.

Does it make sense so far?

In addition, you might have noticed that there was one PushbuttonExample2.pushbutton folder that is not shown in Revit UI.

Just remember that If a button isn’t showing up in Revit you need to check:

  • Typos in folder names, especially sufixes.

  • Is it included in bundle.yamlfile.

Customizing Button Layout with bundle.yaml

Probably you wonder what is bundle.yaml file and why do we need it?

bundle.yaml is an optional file that can hold additional information about the folder where it's located such as layout order. You can delete it and your extension will still work fine.


If you want to control layout of your buttons or panels you have 2 options:

  • Use naming for ordering

  • Use bundle.yaml to specify order


Firstly, keep in mind that you can order your buttons with naming.

For example:

  • 📁button1_Name.pushbutton

  • 📁button2_Name.pushbutton

This way these buttons will show up in the same order as their names inside of Revit. It's a simple and quick way to organize your files.


However, if you want to order your button no matter how you name folders, and to control what is shown or hidden, then you should consider using bundle.yaml file.

Inside you need to use layout keyword and then specify folder names without suffixes.

Here is a sample:

layout

💡Reload pyRevit after you apply changes. Sometimes you might even need to restart Revit.

💡Your can also control order of .panels

Removing Unwanted Buttons or Panels

Now let's clean up your extension and get rid of a few panels or pushbuttons that you don't want. Based on everything we've just talked about it can't be any simpler.

Just find corresponding folders and delete them and it will be gone in Revit after you reload pyRevit. It's that simple…

If you need help finding the right folders, use [ALT] + [Click] inside of Revit to open source folders of your buttons.

Now practice it by removing something like About or LearnRevitAPI panels.

Adding a New Button

Alright, so what about creating new buttons?

As you've already guessed it, we can duplicate any pushbutton folder and it will create a new button after reloading pyRevit. Or you can create it from scratch.

You will see that each pushbutton folder has:

  • script.py- python Script for your button (more on that later…)

  • icon.png - Shown Icon in Revit (Should be under 96x96px)

💡Tip: Button Names are controlled inside of script.py file with __title__ = 'Name' variable. So, don't overthink you folder names but it's best to keep them unique.

💡You can also see icon.dark.png for dark theme or .xaml for custom GUI.

Practice creating new pushbutton

Now let's practice a little. I want you to create a new button in your extension.

Open one of the panel folder and duplicate existing pushbutton.

  1. Duplicate pushbutton

  2. Rename pushbutton folder

  3. Find new icon (or leave existing)

  4. Change __title__ = 'Button Name' inside of script.py file

  • Don't worry about the rest of the code for now, we talk about it another time.
    You just need to create a new button in Revit Toolbar.

Download an Icon

To get a new icon you can use icons8.com website or any other one. Just make sure it's smaller than 96x96px.

You can also place 2 icons for Light and Dark themes by using the following names:

  • icon.png

  • icon.dark.png

Tips for Managing Extensions
  • Keep Dev.panel for work in progress buttons. You can always move pushbutton folders to another panels once they are ready.

  • Stay Organized and use clear names for your folders so you can quickly locate and edit your scripts.

  • Don't be afraid to experiment. Remember it's just a folder structure

  • Don't neglect backups. You don't want to lose your toolbar with all your awesome tools. Trust me on that one.

What’s Next

Alright, and by this point you should know how to personalize your extension to your own needs.

  • You know how Folder Structure relates to your toolbar's layout

  • You know how to Sort and Hide your tools

  • You know how to Add or Remove more buttons

  • And you should start to feel your new super power in Revit

And now it's time for you to practice what you've learnt. I want you to customize your extension by removing panels or buttons you don't need and then adding at least 1 new pushbutton just to practice. It won't take long if you paid attention.


And once you've finished with the homework it's actually time to make these buttons do something useful. And you will love the next lesson as I will show you where you can find a lot of reusable code and how you can make it work for you.

So, see you soon in the next lesson!

HomeWork

Apply what you've learnt during this lesson to customize your own custom Toolbar in Revit.

  • Remove Panels/Pushbuttons you don't need

  • Create New Pushbutton

⌨️ Happy Coding!

Questions:

Order of buttons is wrong with bundle.yaml

Order of buttons is wrong with bundle.yaml

Discuss the lesson :

P.S. Sometimes this chat might experience connection issues.

Use Discord App for best experience.

Discuss the lesson :

P.S. Sometimes this chat might experience connection issues.

Use Discord App for best experience.

Discuss the lesson :

P.S. Sometimes this chat might experience connection issues.

Use Discord App for best experience.

Unlock Community

The pyRevit Hackers Community is only available with pyRevit Hackers Bundle.
Upgrade Here to Get Access to the community and all pyRevit Courses.

Use coupon code "upgrade" to get 150EUR Discount as a member.

⌨️ Happy Coding!

Unlock Community

The pyRevit Hackers Community is only available with pyRevit Hackers Bundle.
Upgrade Here to Get Access to the community and all pyRevit Courses.

Use coupon code "upgrade" to get 150EUR Discount as a member.

⌨️ Happy Coding!

Unlock Community

The pyRevit Hackers Community is only available with pyRevit Hackers Bundle.
Upgrade Here to Get Access to the community and all pyRevit Courses.

Use coupon code "upgrade" to get 150EUR Discount as a member.

⌨️ Happy Coding!

© 2023-2024 EF Learn Revit API

© 2023-2024 EF Learn Revit API

© 2023-2024 EF Learn Revit API