Issue Description
When using custom WPF forms in PyRevit scripts, there appears to be a dependency on having at least one PyRevit DialogTask window open in Revit 2024. Without an open DialogTask, the custom WPF forms either don’t appear or cause the application to freeze.
Environment Details
- Revit Versions Tested:
- Revit 2024.3 ( Issue present)
- Revit 2025.4 ( Working correctly)
- PyRevit Versions Tested:
- 5.0.0.24354
- 5.0.0.24315
Behavior
-
In Revit 2024.3:
- First execution of a script with custom WPF forms fails unless a PyRevit DialogTask is already open
- Subsequent executions may cause the UI to freeze
- The script works properly only when at least one PyRevit dialog (e.g., a search dialog or any other PyRevit window) is open
- The issue persists even with proper form cleanup and disposal
-
In Revit 2025.4:
- All functionality works as expected
- No dependency on having PyRevit dialogs open
- Custom WPF forms display and close properly
Attempted Solutions
- Implemented proper form cleanup and disposal
- Added Windows Forms message pump handling
- Ensured proper UI thread synchronization
- Added explicit disposal of dialog resources
Code Examples
Example 1: Complex UI with Multiple Components
The issue occurs with custom WPF forms created using custom dp_forms
:
from dp_forms import dp_MainUI, dp__AlertMessage
def show_dialog(dialog):
"""Show dialog with proper cleanup."""
try:
if hasattr(dialog, 'show'):
dialog.show()
else:
dialog.ShowDialog()
finally:
if hasattr(dialog, 'Dispose'):
dialog.Dispose()
WinFormsApp.DoEvents()
# Example usage
ui = dp_MainUI(
title="Window Title",
components=[...],
show_cancel=True
)
show_dialog(ui)
Example 2: Simple Alert Message
Even simple alert messages are affected:
from dp_forms import dp__AlertMessage
# Simple alert message that won't show up without a PyRevit dialog open
alert = dp__AlertMessage(
msg="Error:",
sub_msg="No valid beam types found.",
title="Error"
)
alert.ShowDialog() # This will fail unless a PyRevit dialog is already open
Impact
This issue affects any PyRevit script that uses custom WPF forms in Revit 2024, requiring users to have a PyRevit dialog open before executing scripts with custom forms. This creates an unintuitive and potentially confusing user experience.
Questions
- Is this a known issue with WPF handling in PyRevit for Revit 2024?
- Are there any workarounds besides having a PyRevit dialog open?
- Could this be related to changes in how Revit 2024 handles WPF windows compared to Revit 2025?
Additional Notes
- The issue seems specific to custom WPF forms and doesn’t affect native PyRevit forms
- The behavior is consistent across different PyRevit versions tested
- The problem appears to be related to the WPF window handling mechanism in Revit 2024