pyrevit.forms

Reusable WPF forms for pyRevit.

Example

>>> from pyrevit.forms import WPFWindow
class pyrevit.forms.CommandSwitchWindow(context, title, width, height, **kwargs)

Standard form to select from a list of command options.

Parameters:
  • context (list[str]) – list of command options to choose from
  • switches (list[str]) – list of on/off switches
  • message (str) – window title message
  • config (dict) – dictionary of config dicts for options or switches
  • recognize_access_key (bool) – recognize ‘_’ as mark of access key
Returns:

name of selected option

Return type:

str

Returns:

if switches option is used, returns a tuple of selection option name and dict of switches

Return type:

tuple(str, dict)

Example

This is an example with series of command options:

>>> from pyrevit import forms
>>> ops = ['option1', 'option2', 'option3', 'option4']
>>> forms.CommandSwitchWindow.show(ops, message='Select Option')
'option2'

A more advanced example of combining command options, on/off switches, and option or switch configuration options:

>>> from pyrevit import forms
>>> ops = ['option1', 'option2', 'option3', 'option4']
>>> switches = ['switch1', 'switch2']
>>> cfgs = {'option1': { 'background': '0xFF55FF'}}
>>> rops, rswitches = forms.CommandSwitchWindow.show(
...     ops,
...     switches=switches
...     message='Select Option',
...     config=cfgs,
...     recognize_access_key=False
...     )
>>> rops
'option2'
>>> rswitches
{'switch1': False, 'switch2': True}
handle_click(sender, args)

Handle mouse click.

handle_input_key(sender, args)

Handle keyboard inputs.

process_option(sender, args)

Handle click on command option button.

search_txt_changed(sender, args)

Handle text change in search box.

class pyrevit.forms.GetValueWindow(context, title, width, height, **kwargs)

Standard form to get simple values from user.

Args:

Example

>>> from pyrevit import forms
>>> items = ['item1', 'item2', 'item3']
>>> forms.SelectFromList.show(items, button_name='Select Item')
>>> ['item1']
select(sender, args)

Process input data and set the response.

string_value_changed(sender, args)

Handle string vlaue update event.

class pyrevit.forms.ParamDef(name, istype)

Parameter definition tuple.

name

parameter name

Type:str
istype

true if type parameter, otherwise false

Type:bool
istype

Alias for field number 1

name

Alias for field number 0

class pyrevit.forms.ProgressBar(height=32, **kwargs)

Show progress bar at the top of Revit window.

Parameters:
  • title (string) – progress bar text, defaults to 0/100 progress format
  • indeterminate (bool) – create indeterminate progress bar
  • cancellable (bool) – add cancel button to progress bar
  • step (int) – update progress intervals

Example

>>> from pyrevit import forms
>>> count = 1
>>> with forms.ProgressBar(title='my command progress message') as pb:
...    # do stuff
...    pb.update_progress(count, 100)
...    count += 1

Progress bar title could also be customized to show the current and total progress values. In example below, the progress bar message will be in format “0 of 100”

>>> with forms.ProgressBar(title='{value} of {max_value}') as pb:

By default progress bar updates the progress every time the .update_progress method is called. For operations with a large number of max steps, the gui update process time will have a significate effect on the overall execution time of the command. In these cases, set the value of step argument to something larger than 1. In example below, the progress bar updates once per every 10 units of progress.

>>> with forms.ProgressBar(title='message', steps=10):

Progress bar could also be set to indeterminate for operations of unknown length. In this case, the progress bar will show an infinitely running ribbon:

>>> with forms.ProgressBar(title='message', indeterminate=True):

if cancellable is set on the object, a cancel button will show on the progress bar and .cancelled attribute will be set on the ProgressBar instance if users clicks on cancel button:

>>> with forms.ProgressBar(title='message',
...                        cancellable=True) as pb:
...    # do stuff
...    if pb.cancelled:
...        # wrap up and cancel operation
clicked_cancel(sender, args)

Handler for cancel button clicked event.

indeterminate

Progress bar indeterminate state.

reset()

Reset progress value to 0.

title

Progress bar title.

update_progress(new_value, max_value=1)

Update progress bar state with given min, max values.

Parameters:
  • new_value (float) – current progress value
  • max_value (float) – total progress value
wait_async(func, args=())

Call a method asynchronosely and show progress.

class pyrevit.forms.RevisionOption(revision_element)

Revision wrapper for select_revisions().

name

Revision name (description).

class pyrevit.forms.SearchPrompt(search_db, width, height, **kwargs)

Standard prompt for pyRevit search.

Parameters:
  • search_db (list) – list of possible search targets
  • search_tip (str) – text to show in grayscale when search box is empty
  • switches (str) – list of switches
  • width (int) – width of search prompt window
  • height (int) – height of search prompt window
Returns:

matched strings, and dict of switches if provided str: matched string if switches are not provided.

Return type:

str, dict

Example

>>> from pyrevit import forms
>>> # assume search input of '/switch1 target1'
>>> matched_str, args, switches = forms.SearchPrompt.show(
...     search_db=['target1', 'target2', 'target3', 'target4'],
...     switches=['/switch1', '/switch2'],
...     search_tip='pyRevit Search'
...     )
... matched_str
'target1'
... args
['--help', '--branch', 'branchname']
... switches
{'/switch1': True, '/switch2': False}
find_direct_match(input_text)

Find direct text matches in search term.

find_word_match(input_text)

Find direct word matches in search term.

handle_kb_key(sender, args)

Handle keyboard input event.

search_input

Current search input.

search_input_parts

Current cleaned up search term.

search_matches

List of matches for the given search term.

search_term

Current cleaned up search term.

search_term_args

Find arguments in search term.

search_term_main

Current cleaned up search term without the listed switches.

search_term_switches

Find matching switches in search term.

search_txt_changed(sender, args)

Handle text changed event.

set_search_results(*args)

Set search results for returning.

classmethod show(search_db, width=600, height=100, **kwargs)

Show search prompt.

update_results_display(fill_match=False)

Update search prompt results based on current input text.

class pyrevit.forms.SelectFromList(context, title, width, height, **kwargs)

Standard form to select from a list of items.

Any object can be passed in a list to the context argument. This class wraps the objects passed to context, in TemplateListItem. This class provides the necessary mechanism to make this form work both for selecting items from a list, and from a list of checkboxes. See the list of arguments below for additional options and features.

Parameters:
  • context (list[str] or dict[list[str]]) – list of items to be selected from OR dict of list of items to be selected from. use dict when input items need to be grouped e.g. List of sheets grouped by sheet set.
  • title (str, optional) – window title. see super class for defaults.
  • width (int, optional) – window width. see super class for defaults.
  • height (int, optional) – window height. see super class for defaults.
  • button_name (str, optional) – name of select button. defaults to ‘Select’
  • name_attr (str, optional) – object attribute that should be read as item name.
  • multiselect (bool, optional) – allow multi-selection (uses check boxes). defaults to False
  • return_all (bool, optional) – return all items. This is handly when some input items have states and the script needs to check the state changes on all items. This options works in multiselect mode only. defaults to False
  • filterfunc (function) – filter function to be applied to context items.
  • group_selector_title (str) – title for list group selector. defaults to ‘List Group’
  • default_group (str) – name of defautl group to be selected

Example

>>> from pyrevit import forms
>>> items = ['item1', 'item2', 'item3']
>>> forms.SelectFromList.show(items, button_name='Select Item')
>>> ['item1']
>>> from pyrevit import forms
>>> ops = [viewsheet1, viewsheet2, viewsheet3]
>>> res = forms.SelectFromList.show(ops,
...                                 multiselect=False,
...                                 name_attr='Name',
...                                 button_name='Select Sheet')
>>> from pyrevit import forms
>>> ops = {'Sheet Set A': [viewsheet1, viewsheet2, viewsheet3],
...        'Sheet Set B': [viewsheet4, viewsheet5, viewsheet6]}
>>> res = forms.SelectFromList.show(ops,
...                                 multiselect=True,
...                                 name_attr='Name',
...                                 group_selector_title='Sheet Sets',
...                                 button_name='Select Sheets')

This module also provides a wrapper base class TemplateListItem for when the checkbox option is wrapping another element, e.g. a Revit ViewSheet. Derive from this base class and define the name property to customize how the checkbox is named on the dialog.

>>> from pyrevit import forms
>>> class MyOption(forms.TemplateListItem)
...    @property
...    def name(self):
...        return '{} - {}{}'.format(self.item.SheetNumber,
...                                  self.item.SheetNumber)
>>> ops = [MyOption('op1'), MyOption('op2', True), MyOption('op3')]
>>> res = forms.SelectFromList.show(ops,
...                                 multiselect=True,
...                                 button_name='Select Item')
>>> [bool(x) for x in res]  # or [x.state for x in res]
[True, False, True]
button_select(sender, args)

Handle select button click.

check_all(sender, args)

Handle check all button to mark all check boxes as checked.

check_selected(sender, args)

Mark selected checkboxes as checked.

Clear search box.

search_txt_changed(sender, args)

Handle text change in search box.

toggle_all(sender, args)

Handle toggle all button to toggle state of all check boxes.

uncheck_all(sender, args)

Handle uncheck all button to mark all check boxes as un-checked.

uncheck_selected(sender, args)

Mark selected checkboxes as unchecked.

class pyrevit.forms.SheetOption(sheet_element)

Sheet wrapper for select_sheets().

name

Sheet name.

number

Sheet number.

class pyrevit.forms.TemplateListItem(orig_item, checkable=True, name_attr=None)

Base class for checkbox option wrapping another object.

checkable

List Item CheckBox Visibility.

classmethod is_checkbox(item)

Check if the object has all necessary attribs for a checkbox.

name

Name property.

unwrap()

Unwrap and return wrapped object.

class pyrevit.forms.TemplatePromptBar(height=32, **kwargs)

Template context-manager class for creating prompt bars.

Prompt bars are show at the top of the active Revit window and are designed for better prompt visibility.

Parameters:
  • height (int) – window height
  • **kwargs – other arguments to be passed to _setup()
update_window()

Update the prompt bar to match Revit window.

class pyrevit.forms.TemplateUserInputWindow(context, title, width, height, **kwargs)

Base class for pyRevit user input standard forms.

Parameters:
  • context (any) – window context element(s)
  • title (str) – window title
  • width (int) – window width
  • height (int) – window height
  • **kwargs – other arguments to be passed to _setup()
classmethod show(context, title='User Input', width=500, height=400, **kwargs)

Show user input window.

Parameters:
  • context (any) – window context element(s)
  • title (str) – window title
  • width (int) – window width
  • height (int) – window height
  • **kwargs (any) – other arguments to be passed to window
class pyrevit.forms.ViewOption(view_element)

View wrapper for select_views().

name

View name.

class pyrevit.forms.WPFWindow(xaml_source, literal_string=False, handle_esc=True)

WPF Window base class for all pyRevit forms.

Parameters:
  • xaml_source (str) – xaml source filepath or xaml content
  • literal_string (bool) – xaml_source contains xaml content, not filepath
  • handle_esc (bool) – handle Escape button and close the window

Example

>>> from pyrevit import forms
>>> layout = '<Window ' \
>>>          'xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" ' \
>>>          'xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" ' \
>>>          'ShowInTaskbar="False" ResizeMode="NoResize" ' \
>>>          'WindowStartupLocation="CenterScreen" ' \
>>>          'HorizontalContentAlignment="Center">' \
>>>          '</Window>'
>>> w = forms.WPFWindow(layout, literal_string=True)
>>> w.show()
static disable_element(*wpf_elements)

Enable elements.

Parameters:*wpf_elements – WPF framework elements to be enabled
static enable_element(*wpf_elements)

Enable elements.

Parameters:*wpf_elements – WPF framework elements to be enabled
handle_input_key(sender, args)

Handle keyboard input and close the window on Escape.

handle_url_click(sender, args)

Callback for handling click on package website url

static hide_element(*wpf_elements)

Collapse elements.

Parameters:*wpf_elements – WPF framework elements to be collaped
pyrevit_version

Active pyRevit formatted version e.g. ‘4.9-beta’

set_image_source(wpf_element, image_file)

Set source file for image element.

Parameters:
  • element_name (System.Windows.Controls.Image) – xaml image element
  • image_file (str) – image file path
setup_icon()

Setup default window icon.

show(modal=False)

Show window.

show_dialog()

Show modal window.

static show_element(*wpf_elements)

Show collapsed elements.

Parameters:*wpf_elements – WPF framework elements to be set to visible.
static toggle_element(*wpf_elements)

Toggle visibility of elements.

Parameters:*wpf_elements – WPF framework elements to be toggled.
class pyrevit.forms.WarningBar(height=32, **kwargs)

Show warning bar at the top of Revit window.

Parameters:title (string) – warning bar text

Example

>>> with WarningBar(title='my warning'):
...    # do stuff
pyrevit.forms.alert(msg, title=None, sub_msg=None, expanded=None, footer='', ok=True, cancel=False, yes=False, no=False, retry=False, warn_icon=True, options=None, exitscript=False)

Show a task dialog with given message.

Parameters:
  • msg (str) – message to be displayed
  • title (str, optional) – task dialog title
  • ok (bool, optional) – show OK button, defaults to True
  • cancel (bool, optional) – show Cancel button, defaults to False
  • yes (bool, optional) – show Yes button, defaults to False
  • no (bool, optional) – show NO button, defaults to False
  • retry (bool, optional) – show Retry button, defaults to False
  • options (list[str], optional) – list of command link titles in order
  • exitscript (bool, optional) – exit if cancel or no, defaults to False
Returns:

True if okay, yes, or retry, otherwise False

Return type:

bool

Example

>>> from pyrevit import forms
>>> forms.alert('Are you sure?',
...              ok=False, yes=True, no=True, exitscript=True)
pyrevit.forms.alert_ifnot(condition, msg, *args, **kwargs)

Show a task dialog with given message if condition is NOT met.

Parameters:
  • condition (bool) – condition to test
  • msg (str) – message to be displayed
  • title (str, optional) – task dialog title
  • ok (bool, optional) – show OK button, defaults to True
  • cancel (bool, optional) – show Cancel button, defaults to False
  • yes (bool, optional) – show Yes button, defaults to False
  • no (bool, optional) – show NO button, defaults to False
  • retry (bool, optional) – show Retry button, defaults to False
  • exitscript (bool, optional) – exit if cancel or no, defaults to False
Returns:

True if okay, yes, or retry, otherwise False

Return type:

bool

Example

>>> from pyrevit import forms
>>> forms.alert_ifnot(value > 12,
...                   'Are you sure?',
...                    ok=False, yes=True, no=True, exitscript=True)
pyrevit.forms.ask_for_date(default=None, prompt=None, title=None, **kwargs)

Ask user to select a date value.

This is a shortcut function that configures GetValueWindow for date data types. kwargs can be used to pass on other arguments.

Parameters:
  • default (datetime.datetime) – default selected date value
  • prompt (str) – prompt message
  • title (str) – title message
  • kwargs (type) – other arguments to be passed to GetValueWindow
Returns:

selected date

Return type:

datetime.datetime

Example

>>> forms.ask_for_date(default="", title="Enter deadline:")
... datetime.datetime(2019, 5, 17, 0, 0)
pyrevit.forms.ask_for_one_item(items, default=None, prompt=None, title=None, **kwargs)

Ask user to select an item from a list of items.

This is a shortcut function that configures GetValueWindow for ‘single-select’ data types. kwargs can be used to pass on other arguments.

Parameters:
  • items (list[str]) – list of items to choose from
  • default (str) – default selected item
  • prompt (str) – prompt message
  • title (str) – title message
  • kwargs (type) – other arguments to be passed to GetValueWindow
Returns:

selected item

Return type:

str

Example

>>> forms.ask_for_one_item(
...     ['test item 1', 'test item 2', 'test item 3'],
...     default='test item 2',
...     prompt='test prompt',
...     title='test title'
... )
... 'test item 1'
pyrevit.forms.ask_for_string(default=None, prompt=None, title=None, **kwargs)

Ask user to select a string value.

This is a shortcut function that configures GetValueWindow for string data types. kwargs can be used to pass on other arguments.

Parameters:
  • default (str) – default unique string. must not be in reserved_values
  • prompt (str) – prompt message
  • title (str) – title message
  • kwargs (type) – other arguments to be passed to GetValueWindow
Returns:

selected string value

Return type:

str

Example

>>> forms.ask_for_string(
...     default='some-tag',
...     prompt='Enter new tag name:',
...     title='Tag Manager')
... 'new-tag'
pyrevit.forms.ask_for_unique_string(reserved_values, default=None, prompt=None, title=None, **kwargs)

Ask user to select a unique string value.

This is a shortcut function that configures GetValueWindow for unique string data types. kwargs can be used to pass on other arguments.

Parameters:
  • reserved_values (list[str]) – list of reserved (forbidden) values
  • default (str) – default unique string. must not be in reserved_values
  • prompt (str) – prompt message
  • title (str) – title message
  • kwargs (type) – other arguments to be passed to GetValueWindow
Returns:

selected unique string

Return type:

str

Example

>>> forms.ask_for_unique_string(
...     prompt='Enter a Unique Name',
...     title=self.Title,
...     reserved_values=['Ehsan', 'Gui', 'Guido'],
...     owner=self)
... 'unique string'

In example above, owner argument is provided to be passed to underlying GetValueWindow.

pyrevit.forms.check_familydoc(doc=None, family_cat=None, exitscript=False)

Verify document is a Family and notify user if not.

Parameters:
  • doc (DB.Document) – target document, current of not provided
  • family_cat (str) – family category name
  • exitscript (bool) – exit script if returning False
Returns:

True if doc is a Family and of provided category

Return type:

bool

Example

>>> from pyrevit import forms
>>> forms.check_familydoc(doc=revit.doc, family_cat='Data Devices')
... True
pyrevit.forms.check_modeldoc(doc=None, exitscript=False)

Verify document is a not a Model and notify user if not.

Parameters:
  • doc (DB.Document) – target document, current of not provided
  • exitscript (bool) – exit script if returning False
Returns:

True if doc is a Model

Return type:

bool

Example

>>> from pyrevit import forms
>>> forms.check_modeldoc(doc=revit.doc)
... True
pyrevit.forms.check_selection(exitscript=False, message='At least one element must be selected.')

Verify if selection is not empty notify user if it is.

Parameters:
  • exitscript (bool) – exit script if returning False
  • message (str) – prompt message if returning False
Returns:

True if selection has at least one item

Return type:

bool

pyrevit.forms.check_workshared(doc=None, message='Model is not workshared.')

Verify if model is workshared and notify user if not.

Parameters:
  • doc (DB.Document) – target document, current of not provided
  • message (str) – prompt message if returning False
Returns:

True if doc is workshared

Return type:

bool

pyrevit.forms.inform_wip()

Show work-in-progress prompt to user and exit script.

Example

>>> forms.inform_wip()
pyrevit.forms.pick_excel_file(save=False)

File pick/save dialog for an excel file.

Parameters:save (bool) – show file save dialog, instead of file pick dialog
Returns:file path
Return type:str
pyrevit.forms.pick_file(file_ext='', files_filter='', init_dir='', restore_dir=True, multi_file=False, unc_paths=False)

Pick file dialog to select a destination file.

Parameters:
  • file_ext (str) – file extension
  • files_filter (str) – file filter
  • init_dir (str) – initial directory
  • restore_dir (bool) – restore last directory
  • multi_file (bool) – allow select multiple files
  • unc_paths (bool) – return unc paths
Returns:

file path or list of file paths if multi_file=True

Return type:

str or list[str]

Example

>>> from pyrevit import forms
>>> forms.pick_file(file_ext='csv')
... r'C:\output\somefile.csv'
>>> forms.pick_file(file_ext='csv', multi_file=True)
... [r'C:\output\somefile1.csv', r'C:\output\somefile2.csv']
>>> forms.pick_file(files_filter='All Files (*.*)|*.*|'
                                 'Excel Workbook (*.xlsx)|*.xlsx|'
                                 'Excel 97-2003 Workbook|*.xls',
                    multi_file=True)
... [r'C:\output\somefile1.xlsx', r'C:\output\somefile2.xls']
pyrevit.forms.pick_folder(title=None)

Show standard windows pick folder dialog.

Parameters:title (str, optional) – title for the window
Returns:folder path
Return type:str
pyrevit.forms.save_excel_file()

File save dialog for an excel file.

Returns:file path
Return type:str
pyrevit.forms.save_file(file_ext='', files_filter='', init_dir='', default_name='', restore_dir=True, unc_paths=False)

Save file dialog to select a destination file for data.

Parameters:
  • file_ext (str) – file extension
  • files_filter (str) – file filter
  • init_dir (str) – initial directory
  • default_name (str) – default file name
  • restore_dir (bool) – restore last directory
  • unc_paths (bool) – return unc paths
Returns:

file path

Return type:

str

Example

>>> from pyrevit import forms
>>> forms.save_file(file_ext='csv')
... r'C:\output\somefile.csv'
pyrevit.forms.select_image(images, title='Select Image', button_name='Select')

Standard form for selecting an image.

Parameters:
  • images (list[str] | list[framework.Imaging.BitmapImage]) – list of image file paths or bitmaps
  • title (str, optional) – swatch list window title
  • button_name (str, optional) – swatch list window button caption
Returns:

path of the selected image

Return type:

str

Example

>>> from pyrevit import forms
>>> forms.select_image(['C:/path/to/image1.png',
                        'C:/path/to/image2.png'],
                        title="Select Variation")
... 'C:/path/to/image1.png'
pyrevit.forms.select_open_docs(title='Select Open Documents', button_name='OK', width=500, multiple=True, filterfunc=None)

Standard form for selecting open documents.

Parameters:
  • title (str, optional) – list window title
  • button_name (str, optional) – list window button caption
  • width (int, optional) – width of list window
  • multiselect (bool, optional) – allow multi-selection (uses check boxes). defaults to True
  • filterfunc (function) – filter function to be applied to context items.
Returns:

list of selected documents

Return type:

list[DB.Document]

Example

>>> from pyrevit import forms
>>> forms.select_open_docs()
... [<Autodesk.Revit.DB.Document object>,
...  <Autodesk.Revit.DB.Document object>]
pyrevit.forms.select_parameter(src_element, title='Select Parameters', button_name='Select', multiple=True, filterfunc=None, include_instance=True, include_type=True)

Standard form for selecting parameters from given element.

Parameters:
  • src_element (DB.Element) – source element
  • title (str, optional) – list window title
  • button_name (str, optional) – list window button caption
  • multiselect (bool, optional) – allow multi-selection (uses check boxes). defaults to True
  • filterfunc (function) – filter function to be applied to context items.
  • include_instance (bool, optional) – list instance parameters
  • include_type (bool, optional) – list type parameters
Returns:

list of paramdef objects

Return type:

list[ParamDef]

Example

>>> forms.select_parameter(
...     src_element,
...     title='Select Parameters',
...     multiple=True,
...     include_instance=True,
...     include_type=True
... )
... [<ParamDef >, <ParamDef >]
pyrevit.forms.select_revisions(title='Select Revision', button_name='Select', width=500, multiple=True, filterfunc=None, doc=None)

Standard form for selecting revisions.

Parameters:
  • title (str, optional) – list window title
  • button_name (str, optional) – list window button caption
  • width (int, optional) – width of list window
  • multiselect (bool, optional) – allow multi-selection (uses check boxes). defaults to True
  • filterfunc (function) – filter function to be applied to context items.
  • doc (DB.Document, optional) – source document for revisions; defaults to active document
Returns:

list of selected revisions

Return type:

list[DB.Revision]

Example

>>> from pyrevit import forms
>>> forms.select_revisions()
... [<Autodesk.Revit.DB.Revision object>,
...  <Autodesk.Revit.DB.Revision object>]
pyrevit.forms.select_sheets(title='Select Sheets', button_name='Select', width=500, multiple=True, filterfunc=None, doc=None)

Standard form for selecting sheets.

Sheets are grouped into sheet sets and sheet set can be selected from a drop down box at the top of window.

Parameters:
  • title (str, optional) – list window title
  • button_name (str, optional) – list window button caption
  • width (int, optional) – width of list window
  • multiselect (bool, optional) – allow multi-selection (uses check boxes). defaults to True
  • filterfunc (function) – filter function to be applied to context items.
  • doc (DB.Document, optional) – source document for sheets; defaults to active document
Returns:

list of selected sheets

Return type:

list[DB.ViewSheet]

Example

>>> from pyrevit import forms
>>> forms.select_sheets()
... [<Autodesk.Revit.DB.ViewSheet object>,
...  <Autodesk.Revit.DB.ViewSheet object>]
pyrevit.forms.select_swatch(title='Select Color Swatch', button_name='Select')

Standard form for selecting a color swatch.

Parameters:
  • title (str, optional) – swatch list window title
  • button_name (str, optional) – swatch list window button caption
Returns:

rgb color

Return type:

pyrevit.coreutils.colors.RGB

Example

>>> from pyrevit import forms
>>> forms.select_swatch(title="Select Text Color")
... <RGB #CD8800>
pyrevit.forms.select_titleblocks(title='Select Titleblock', button_name='Select', no_tb_option='No Title Block', width=500, multiple=False, filterfunc=None, doc=None)

Standard form for selecting a titleblock.

Parameters:
  • title (str, optional) – list window title
  • button_name (str, optional) – list window button caption
  • no_tb_option (str, optional) – name of option for no title block
  • width (int, optional) – width of list window
  • multiselect (bool, optional) – allow multi-selection (uses check boxes). defaults to True
  • filterfunc (function) – filter function to be applied to context items.
  • doc (DB.Document, optional) – source document for titleblocks; defaults to active document
Returns:

selected titleblock id.

Return type:

DB.ElementId

Example

>>> from pyrevit import forms
>>> forms.select_titleblocks()
... <Autodesk.Revit.DB.ElementId object>
pyrevit.forms.select_views(title='Select Views', button_name='Select', width=500, multiple=True, filterfunc=None, doc=None)

Standard form for selecting views.

Parameters:
  • title (str, optional) – list window title
  • button_name (str, optional) – list window button caption
  • width (int, optional) – width of list window
  • multiselect (bool, optional) – allow multi-selection (uses check boxes). defaults to True
  • filterfunc (function) – filter function to be applied to context items.
  • doc (DB.Document, optional) – source document for views; defaults to active document
Returns:

list of selected views

Return type:

list[DB.View]

Example

>>> from pyrevit import forms
>>> forms.select_views()
... [<Autodesk.Revit.DB.View object>,
...  <Autodesk.Revit.DB.View object>]
pyrevit.forms.select_viewtemplates(title='Select View Templates', button_name='Select', width=500, multiple=True, filterfunc=None, doc=None)

Standard form for selecting view templates.

Parameters:
  • title (str, optional) – list window title
  • button_name (str, optional) – list window button caption
  • width (int, optional) – width of list window
  • multiselect (bool, optional) – allow multi-selection (uses check boxes). defaults to True
  • filterfunc (function) – filter function to be applied to context items.
  • doc (DB.Document, optional) – source document for views; defaults to active document
Returns:

list of selected view templates

Return type:

list[DB.View]

Example

>>> from pyrevit import forms
>>> forms.select_viewtemplates()
... [<Autodesk.Revit.DB.View object>,
...  <Autodesk.Revit.DB.View object>]
pyrevit.forms.toast(message, title='pyRevit', appid='pyRevit', icon=None, click=None, actions=None)

Show a Windows 10 notification.

Parameters:
  • message (str) – notification message
  • title (str) – notification title
  • appid (str) – app name (will show under message)
  • icon (str) – file path to icon .ico file (defaults to pyRevit icon)
  • click (str) – click action commands string
  • actions (dict) – dictionary of button names and action strings

Example

>>> script.toast("Hello World!",
...              title="My Script",
...              appid="MyAPP",
...              click="https://eirannejad.github.io/pyRevit/",
...              actions={
...                  "Open Google":"https://google.com",
...                  "Open Toast64":"https://github.com/go-toast/toast"
...                  })

pyrevit.forms.toaster

Base module for pushing toast messages on Win 10.

This module is a wrapper for a cli utility that provides toast message functionality. See https://github.com/go-toast/toast

pyrevit.forms.toaster.get_toaster()

Return full file path of the toast binary utility.

pyrevit.forms.toaster.send_toast(message, title=None, appid=None, icon=None, click=None, actions=None)

Send toast notificaton.

Parameters:
  • message (str) – notification message
  • title (str) – notification title
  • appid (str) – application unique id (see –app-id cli option)
  • icon (str) – notification icon (see –icon cli option)
  • click (str) – click action (see –activation-arg cli option)
  • (dict[str (actions) – str]): list of actions (see –action and –action-arg cli options)

pyrevit.forms.utils

Utility functions to support forms module.

pyrevit.forms.utils.bitmap_from_file(bitmap_file)

Create BitmapImage from a bitmap file.

Parameters:bitmap_file (str) – path to bitmap file
Returns:bitmap image object
Return type:BitmapImage
pyrevit.forms.utils.load_component(xaml_file, comp_type)

Load WPF component from xaml file.

Parameters:
  • xaml_file (str) – xaml file path
  • comp_type (System.Windows.Controls) – WPF control type
Returns:

loaded WPF control

Return type:

System.Windows.Controls

pyrevit.forms.utils.load_ctrl_template(xaml_file)

Load System.Windows.Controls.ControlTemplate from xaml file.

Parameters:xaml_file (str) – xaml file path
Returns:loaded control template
Return type:System.Windows.Controls.ControlTemplate
pyrevit.forms.utils.load_itemspanel_template(xaml_file)

Load System.Windows.Controls.ItemsPanelTemplate from xaml file.

Parameters:xaml_file (str) – xaml file path
Returns:loaded items-panel template
Return type:System.Windows.Controls.ControlTemplate