pyrevit.userconfig

Handle reading and parsing, writin and saving of all user configurations.

This module handles the reading and writing of the pyRevit configuration files. It’s been used extensively by pyRevit sub-modules. user_config is set up automatically in the global scope by this module and can be imported into scripts and other modules to access the default configurations.

All other modules use this module to query user config.

Example

>>> from pyrevit.userconfig import user_config
>>> user_config.add_section('newsection')
>>> user_config.newsection.property = value
>>> user_config.newsection.get('property', default_value)
>>> user_config.save_changes()

The user_config object is also the destination for reading and writing configuration by pyRevit scripts through get_config() of pyrevit.script module. Here is the function source:

def get_config(section=None):
    """Create and return config section parser object for current script.

    Args:
        section (str, optional): config section name

    Returns:
        :obj:`pyrevit.coreutils.configparser.PyRevitConfigSectionParser`:
            Config section parser object
    """
    from pyrevit.userconfig import user_config
    if not section:
        script_cfg_postfix = 'config'
        section = EXEC_PARAMS.command_name + script_cfg_postfix

    try:
        return user_config.get_section(section)
    except Exception:
        return user_config.add_section(section)

Example

>>> from pyrevit import script
>>> cfg = script.get_config()
>>> cfg.property = value
>>> cfg.get('property', default_value)
>>> script.save_config()
class pyrevit.userconfig.PyRevitConfig(cfg_file_path=None, config_type='Unknown')

Provide read/write access to pyRevit configuration.

Parameters:
  • cfg_file_path (str) – full path to config file to be used.
  • config_type (str) – type of config file

Example

>>> cfg = PyRevitConfig(cfg_file_path)
>>> cfg.add_section('sectionname')
>>> cfg.sectionname.property = value
>>> cfg.sectionname.get('property', default_value)
>>> cfg.save_changes()
config_file

Current config file path.

get_active_cpython_engine()

Return active cpython engine.

get_config_version()

Return version of config file used for change detection.

static get_current_attachment()

Return current pyRevit attachment.

get_ext_root_dirs()

Return a list of all extension directories.

Returns:list of strings. user extension directories.
Return type:list
static get_list_separator()

Get list separator defined in user os regional settings.

get_thirdparty_ext_root_dirs(include_default=True)

Return a list of external extension directories set by the user.

Returns:list of strings. External user extension directories.
Return type:list
save_changes()

Save user config into associated config file.

set_thirdparty_ext_root_dirs(path_list)

Updates list of external extension directories in config file

Parameters:path_list (list[str]) – list of external extension paths
pyrevit.userconfig.find_config_file(target_path)

Find config file in target path.

pyrevit.userconfig.verify_configs(config_file_path=None)

Create a user settings file.

if config_file_path is not provided, configs will be in memory only

Parameters:config_file_path (str, optional) – config file full name and path
Returns:pyRevit config file handler
Return type:pyrevit.userconfig.PyRevitConfig