All pyRevit python scripts should use the pyrevit.script
module to access pyRevit functionality. pyRevit internals are subject to change and accessing them directly is not suggested. Here is a list of supported modules for pyRevit scripts. This module provides access to output window (pyrevit.output
), logging (pyrevit.coreutils.logger
), temporary files (pyrevit.coreutils.appdata
), and other misc features.
You can get the default logger for the script, and log information related to what your script is doing
from pyrevit import script
logger = script.get_logger()
logger.info('Test Info Log Level :OK_hand:')
logger.success('Test Success Log Level')
logger.debug('Test Debug Log Level')
logger.warning('Test Warning Log Level')
logger.error('Test Error Log Level')
logger.critical('Test Critical Log Level')
logger.deprecate('Test Deprecate Message')
All messages are printed in color for clarity. Normally debug messages are not printed. You can hold CTRL and click on a command button to put that command in DEBUG mode and see all its debug messages.
Each script can control its own output window
<aside> <img src="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/b6be0b32-1969-43e6-b22d-b924e5913e90/ic_01_idea.png" alt="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/b6be0b32-1969-43e6-b22d-b924e5913e90/ic_01_idea.png" width="40px" /> See Effective Output for more information on the output window features
</aside>
from pyrevit import script
output = script.get_output()
output.set_height(600)
output.get_title()
output.set_title('More control please!')
Each script can save and load its own configurations.
from pyrevit import script
config = script.get_config()
# set a new config parameter: firstparam
config.firstparam = True
# saving configurations
script.save_config()
# read the config parameter value
if config.firstparam:
do_task_A()
These configs are saved into the pyRevit’s user configuration file, alongside pyRevit's internal configs and the configurations for other tools. The configs for your tool will be saved under their own config section. The example below shows the configs for the Match tool (partial). Note that all the options are saved under the [Matchconfig]
config section that belongs to the Match tool.
[Matchconfig]
halftone = true
transparency = true
proj_line_color = true
proj_line_pattern = true
proj_line_weight = true
proj_fill_color = true
proj_fill_pattern = true
proj_fill_pattern_visibility = true
proj_bg_fill_color = true
proj_bg_fill_pattern = true
proj_bg_fill_pattern_visibility = true
...