How to remain the pop-up window by pyrevit.forms.SelectFromList?

Hi all,

I’m new to here and it’s my first post. If this topic has been covered already, I apologies in advance.

The image above is my first simple tools by using pyrevit.forms.SelectFromList to display all the rooms in the project and select them.

Is there a way to remain this pop-up window after clicking the “Select Room” button? Basically, I need to re-run this script every single time when I selected the room but if this window remains until clicking the x button in top-right corner then I don’t have to re-run this script over and over again.

Below is my source code for this function and appreciate any comments on this;

from Autodesk.Revit.DB import *
from pyrevit import forms
from System.Collections.Generic import List

uidoc = __revit__.ActiveUIDocument

# Retrieve rooms from the document
allrooms = FilteredElementCollector(uidoc.Document)\

# Filter out rooms without a value in the "Number" parameter
valid_rooms = [room for room in allrooms if room.get_Parameter(BuiltInParameter.ROOM_NUMBER).AsString()]

# Sort valid rooms by room number value
sorted_rooms = sorted(valid_rooms, key=lambda room: room.get_Parameter(BuiltInParameter.ROOM_NUMBER).AsString())

# Create a list to store room IDs
room_ids = []

# Define a function to get room number and name as a string
def get_room_number_and_name(room):
    room_number = room.get_Parameter(BuiltInParameter.ROOM_NUMBER).AsString()
    room_name = room.get_Parameter(BuiltInParameter.ROOM_NAME).AsString()
    return room_number + " - " + room_name

# Get the list of room number and name combinations
room_number_name_list = [get_room_number_and_name(room) for room in sorted_rooms]

# Display a selection dialog for the list of room numbers and names
selected_room_numbers_names =, title='Select Room by Number', multiselect=True, button_name='Select Room')

# Check if rooms are selected
if selected_room_numbers_names:
    for selected_room_number_name in selected_room_numbers_names:
        # Find the corresponding room element based on the selected room number and name
        selected_room = next(room for room in sorted_rooms if get_room_number_and_name(room) == selected_room_number_name)

    # Select the rooms in the Revit UI

You would need to make a modeless window to achieve that.

or “while” loop to keep restarting the whole command until you cancel it.

Is there any example or reference I can make my pop-up modeless window?

I can’t recall any pyRevit windows out of the box being modeless. What I’m wortking on currently has a modeless window but with a slightly different purpose, however you might use it as a starting point:

Another one:

As you can see, the included WPFWIndow is somewhat prepared for being shown in modeless form, but needs extra caution and efforts, if you want to interact with the Revit API in that context.

The color splasher is also modeless (but a much bigger chunk of code to digest)

1 Like