Skip to content

envvars

pyRevit managed environment variables framework.

pyRevit provides the environment variables framework to the pyRevit core and all pyRevit tools so they can store arbitary data withing the running host session and share small data quickly between script runs.

Some settings needs to be set for the current session and might need to affect the behaviour of all individual scripts inside the extensions. (e.g. If user activates the DEBUG mode, all scripts should follow and log the debug entries.) The information is saved using AppDomain.GetData and SetData in a dictionary parameter. The dictionary is used to minimize the addition of named parameters to the AppDomain. The dictionary then includes all the internal parameters and their associated value. This way each script does not need to read the usersettings data which reduces io and saves time.

pyRevit uses environment variables extensively at its core and making changes to the core environment variables (starting with PYREVIT_) through scripts is strongly prohibited.

Examples:

from pyrevit.coreutils import envvars
envvars.set_pyrevit_env_var('MY_SCRIPT_STATUS', True)
envvars.set_pyrevit_env_var('MY_SCRIPT_CONFIG', {'someconfig': True})

Then another script or same script when executed later within the same session can query the shared environment variable:

envvars.get_pyrevit_env_vars('MY_SCRIPT_STATUS')
True
envvars.get_pyrevit_env_vars('MY_SCRIPT_CONFIG')
{'someconfig': True}

Attributes

PRODUCT_NAME = str(Common.PyRevitLabsConsts.ProductName).upper() module-attribute

ENV_VAR_DICT_NAME = PRODUCT_NAME + 'EnvVarsDict' module-attribute

SESSIONUUID_ENVVAR = PRODUCT_NAME + '_UUID' module-attribute

APPVERSION_ENVVAR = PRODUCT_NAME + '_APPVERSION' module-attribute

VERSION_ENVVAR = PRODUCT_NAME + '_VERSION' module-attribute

CLONENAME_ENVVAR = PRODUCT_NAME + '_CLONE' module-attribute

IPYVERSION_ENVVAR = PRODUCT_NAME + '_IPYVERSION' module-attribute

CPYVERSION_ENVVAR = PRODUCT_NAME + '_CPYVERSION' module-attribute

LOGGING_LEVEL_ENVVAR = PRODUCT_NAME + '_LOGGINGLEVEL' module-attribute

FILELOGGING_ENVVAR = PRODUCT_NAME + '_FILELOGGING' module-attribute

LOADEDASSMS_ENVVAR = PRODUCT_NAME + '_LOADEDASSMS' module-attribute

REFEDASSMS_ENVVAR = PRODUCT_NAME + '_REFEDASSMS' module-attribute

TELEMETRYSTATE_ENVVAR = PRODUCT_NAME + '_TELEMETRYSTATE' module-attribute

TELEMETRYUTCTIMESTAMPS_ENVVAR = PRODUCT_NAME + '_TELEMETRYUTCTIMESTAMPS' module-attribute

TELEMETRYDIR_ENVVAR = PRODUCT_NAME + '_TELEMETRYDIR' module-attribute

TELEMETRYFILE_ENVVAR = PRODUCT_NAME + '_TELEMETRYFILE' module-attribute

TELEMETRYSERVER_ENVVAR = PRODUCT_NAME + '_TELEMETRYSERVER' module-attribute

TELEMETRYINCLUDEHOOKS_ENVVAR = PRODUCT_NAME + '_TELEMETRYINCLUDEHOOKS' module-attribute

APPTELEMETRYSTATE_ENVVAR = PRODUCT_NAME + '_APPTELEMETRYSTATE' module-attribute

APPTELEMETRYHANDLER_ENVVAR = PRODUCT_NAME + '_APPTELEMETRYHANDLER' module-attribute

APPTELEMETRYSERVER_ENVVAR = PRODUCT_NAME + '_APPTELEMETRYSERVER' module-attribute

APPTELEMETRYEVENTFLAGS_ENVVAR = PRODUCT_NAME + '_APPTELEMETRYEVENTFLAGS' module-attribute

ROUTES_SERVER = PRODUCT_NAME + '_ROUTESSERVER' module-attribute

ROUTES_ROUTES = PRODUCT_NAME + '_ROUTESROUTES' module-attribute

HOOKS_ENVVAR = PRODUCT_NAME + '_HOOKS' module-attribute

HOOKSHANDLER_ENVVAR = PRODUCT_NAME + '_HOOKSHANDLER' module-attribute

AUTOUPDATING_ENVVAR = PRODUCT_NAME + '_AUTOUPDATE' module-attribute

OUTPUT_STYLESHEET_ENVVAR = PRODUCT_NAME + '_STYLESHEET' module-attribute

RIBBONUPDATOR_ENVVAR = PRODUCT_NAME + '_RIBBONUPDATOR' module-attribute

TABCOLORIZER_ENVVAR = PRODUCT_NAME + '_TABCOLORIZER' module-attribute

Functions

get_pyrevit_env_vars()

Get the root dictionary, holding all environment variables.

Source code in pyrevitlib/pyrevit/coreutils/envvars.py
def get_pyrevit_env_vars():
    """Get the root dictionary, holding all environment variables."""
    return AppDomain.CurrentDomain.GetData(ENV_VAR_DICT_NAME)

get_pyrevit_env_var(param_name)

Get value of a parameter shared between all scripts.

Parameters:

Name Type Description Default
param_name str

name of environment variable

required

Returns:

Type Description
object

any object stored as the environment variable value

Source code in pyrevitlib/pyrevit/coreutils/envvars.py
def get_pyrevit_env_var(param_name):
    """Get value of a parameter shared between all scripts.

    Args:
        param_name (str): name of environment variable

    Returns:
        (object): any object stored as the environment variable value
    """
    # This function returns None if it can not find the parameter.
    # Thus value of None should not be used for params

    data_dict = get_pyrevit_env_vars()
    return data_dict.get(param_name) if data_dict else None

set_pyrevit_env_var(param_name, param_value)

Set value of a parameter shared between all scripts.

Parameters:

Name Type Description Default
param_name str

name of environment variable

required
param_value object

any python object

required
Source code in pyrevitlib/pyrevit/coreutils/envvars.py
def set_pyrevit_env_var(param_name, param_value):
    """Set value of a parameter shared between all scripts.

    Args:
        param_name (str): name of environment variable
        param_value (object): any python object
    """
    # Get function returns None if it can not find the parameter.
    # Thus value of None should not be used for params
    data_dict = get_pyrevit_env_vars() or {}
    data_dict[param_name] = param_value
    AppDomain.CurrentDomain.SetData(ENV_VAR_DICT_NAME, data_dict)