Lesson Objectives

Lesson Objectives

  • Learn about reusable pyRevit forms

  • Learn how to use WarningBar during Selection

Are you Ready?

Lesson Summary

Lesson Summary

Improve User Experience during Selection

This is going to be a quick lesson.

I want to show you how to make your seleciton even better by providing a clear message to the user which is really hard to miss (unlike default Autodesk's message…).

And for that we are going to use built-in feature from pyRevit forms which is also super easy to use. For that let's open pyRevit Dev Docs and look into Effective Inputs section.

pyRevit Effective Inputs

This is how this page looks 👉.

As you can see there are going to be code snippets on the left side and image previews on the right.

The beauty of pyRevit forms is that you just copy-paste these code snippets and it works. Then you adjust it to your needs and your UI is complete.

We will use it throughout the course so you will learn more about different available forms, but for now we are interested in WarningBar form.

The Warning Bar Code

As you can see on the screenshot, the WarningBar will create a large orange strip on the top with your custom message. And it's great for explaining user what to do next, as they can't miss it even if they try.

And it's easy to use, here is the code snippet:

from pyrevit import forms

with forms.WarningBar(title='Pick source object:'):
    do_stuff()

You use it as a Context-Manager and then write your logic inside the with-block to display the message. So we just need to put out Selection logic instead of do_stuff() palceholder and it will work.

Select with WarningBar

So here is how we could combine it with PickObject method:

# ⬇️ Imports
from Autodesk.Revit.UI.Selection import ObjectType
from pyrevit import forms

# 👉 Select with WarningBar
with forms.WarningBar(title="Now It's Time For You To Practice!"):
    try:
        ref = uidoc.Selection.PickObject(ObjectType.Element, 'Select Wall')
        elem = doc.GetElement(ref)
        print(elem)
    except:
        print('Selection Cancelled.')

💡Remember that it's always great to use try/except statement during Selection, so you can suppress the warning message if user decides to cancel during selection.

Homework

Homework

Follow the lesson and try using the forms.WarningBar as I shown in the video. It will make a huge difference in how your tool is being used and avoid confusion on what users have to do.


For now, I want you to go and practice using this. It's really, really useful when you want to communicate with users what to do. Try using forms.WarningBar as I shown in the video, it's really useful for selection prompts.

⌨️ Happy Coding!

Questions

Questions

Can I change color of the WarningBar?

Can I change color of the WarningBar?

Discuss Lesson

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

Use Discord App for the best experience.

Discuss Lesson

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

Use Discord App for the best experience.

Discuss Lesson

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

Use Discord App for the best experience.

© 2023-2025 EF Learn Revit API

© 2023-2025 EF Learn Revit API

© 2023-2025 EF Learn Revit API