settings_window
Dynamic Settings Window for pyRevit Creates a reusable WPF window for managing script configurations.
Usage
from pyrevit import script from pyrevit.forms import settings_window
settings = [ {"type": "section", "label": "Display"}, {"name": "scope", "type": "choice", "label": "Scope", "options": ["Visibility", "Active State"], "default": "Visibility"}, {"name": "highlight_color", "type": "color", "label": "Highlight Color", "default": "#ffff0000"},
{"type": "section", "label": "Processing"},
{"name": "set_workset", "type": "bool", "label": "Set Workset", "default": True},
{"name": "tolerance", "type": "slider", "label": "Tolerance (mm)",
"default": 10, "min": 0, "max": 1000},
{"name": "prefix", "type": "string", "label": "Prefix", "default": ""},
{"type": "section", "label": "Paths"},
{"name": "export_folder", "type": "folder", "label": "Export Folder", "default": ""},
{"name": "template_file", "type": "file", "label": "Template File",
"default": "", "file_ext": "rvt", "files_filter": "Revit Files (*.rvt)|*.rvt"},
]
if settings_window.show_settings(settings, title="My Tool Settings"): print("Settings saved!")
Attributes
DEFAULT_MAX_HEIGHT = 560
module-attribute
Classes
SettingsWindow(settings_schema, section=None, title='Settings', width=450, custom_config=None, max_height=DEFAULT_MAX_HEIGHT)
Bases: WPFWindow
Dynamic settings window that generates UI from schema.
Initialize the settings window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings_schema
|
List of setting definitions |
required | |
section
|
Config section name |
None
|
|
title
|
Window title |
'Settings'
|
|
width
|
Window width in pixels |
450
|
|
custom_config
|
Will generate a new ini with the given name. Uses default if not provided. |
None
|
|
max_height
|
Window height cap; past it the settings area scrolls |
DEFAULT_MAX_HEIGHT
|
Source code in pyrevitlib/pyrevit/forms/settings_window.py
Attributes
resolve_theme = True
class-attribute
instance-attribute
configparser = None
instance-attribute
config = self.configparser.get_section(section)
instance-attribute
settings_schema = settings_schema
instance-attribute
window_title = title
instance-attribute
window_width = width
instance-attribute
window_max_height = max_height
instance-attribute
config_section = section
instance-attribute
result = False
instance-attribute
controls = {}
instance-attribute
Title = self.window_title
instance-attribute
Methods:
save_clicked(sender, args)
Handle save button click.
Source code in pyrevitlib/pyrevit/forms/settings_window.py
cancel_clicked(sender, args)
reset_clicked(sender, args)
Handle reset button click.
Source code in pyrevitlib/pyrevit/forms/settings_window.py
Functions:
show_settings(settings_schema, section=None, title='Settings', width=450, custom_config=None, max_height=DEFAULT_MAX_HEIGHT)
Show settings window and return True if saved.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings_schema
|
List of setting definitions. Each entry is a dict with: Structural / display-only (no "name" key required): - type "section" -- bold heading + separator line. Requires "label". - type "separator" -- bare horizontal rule, no label. Interactive settings (all require "name"): - type "bool" -- CheckBox. - type "choice" -- ComboBox. Requires "options" list. - type "slider" -- Slider with live readout. Supports "min", "max", "step". - type "int" -- TextBox validated as integer. Supports "min", "max". - type "float" -- TextBox validated as float. Supports "min", "max". - type "string" -- TextBox. Supports "required" (bool). - type "color" -- TextBox + color-preview swatch + picker button. - type "folder" -- TextBox + folder-browse button. Supports "init_dir". - type "file" -- TextBox + file-browse button. Supports "file_ext", "files_filter", "init_dir", "multi_file". Common optional keys for interactive settings: - name (str): Setting key stored in .ini config. - label (str): Human-readable label shown in the UI. - default: Value used when no config entry exists yet. - required (bool): For "string" / path types — blocks save if empty. |
required | |
section
|
str
|
Config section name (default: None) |
None
|
title
|
str
|
Window title (default: "Settings") |
'Settings'
|
width
|
int
|
Window width in pixels (default: 450) |
450
|
custom_config
|
str
|
Use a custom ini file (default: None) |
None
|
max_height
|
int
|
Window height cap in pixels; a schema taller than this scrolls instead of growing the window off screen (default: DEFAULT_MAX_HEIGHT) |
DEFAULT_MAX_HEIGHT
|
Returns:
| Name | Type | Description |
|---|---|---|
bool |
True if settings were saved, False if canceled/reset. |
Example::
settings_schema = [
{"type": "section", "label": "Display"},
{"name": "scope", "type": "choice", "label": "Scope",
"options": ["Visibility", "Active State"], "default": "Visibility"},
{"name": "highlight_color", "type": "color", "label": "Highlight Color",
"default": "#ffff0000"},
{"type": "section", "label": "Processing"},
{"name": "tolerance", "type": "slider", "label": "Tolerance (mm)",
"default": 10, "min": 0, "max": 1000, "step": 5},
{"name": "set_workset", "type": "bool", "label": "Set Workset",
"default": True},
{"type": "separator"},
{"name": "prefix", "type": "string", "label": "Prefix", "default": ""},
]
if show_settings(settings_schema, section="MyToolSection", title="My Tool Settings"):
print("Settings saved!")
Source code in pyrevitlib/pyrevit/forms/settings_window.py
705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 | |