sessionmgr
The loader module manages the workflow of loading a new pyRevit session.
Its main purpose is to orchestrate the process of finding pyRevit extensions, creating dll assemblies for them, and creating a user interface in the host application.
Everything starts from sessionmgr.load_session() function...
The only public function is load_session() that loads a new session.
Everything else is private.
Attributes
mlogger = logger.get_logger(__name__)
module-attribute
pyrevit_extcmdtype_cache = []
module-attribute
Classes
PyRevitExternalCommandType(extcmd_type, extcmd_availtype)
Bases: object
PyRevit external command type.
Source code in pyrevitlib/pyrevit/loader/sessionmgr.py
Attributes
extcmd_type
property
typename
property
extcmd_availtype
property
avail_typename
property
script
property
config_script
property
search_paths
property
arguments
property
engine_cfgs
property
helpsource
property
tooltip
property
name
property
bundle
property
extension
property
unique_id
property
control_id
property
Methods:
is_available(category_set, zerodoc=False)
Functions:
perform_preload()
Run pre-load session setup before the C# loader builds the UI.
Invoked by the C# session orchestrator as the first step of a load. Sets up the session environment, output window, and pre-load services.
Note
Relies on the Preload entry script having cleared the attachment cache before importing this module, so every attachment lookup in the load reads the current attachment once and then reuses it.
Source code in pyrevitlib/pyrevit/loader/sessionmgr.py
perform_postload()
Finalize the session after the C# loader has built the UI.
Invoked by the C# session orchestrator as the last step of a load. Runs post-load services, registers the assemblies the C# loader produced, reports load time, and tears down the startup output stream.
Returns:
| Type | Description |
|---|---|
str
|
session uuid |
Source code in pyrevitlib/pyrevit/loader/sessionmgr.py
load_session()
Handles loading/reloading of the pyRevit addin and extensions.
Delegates to the C# session orchestrator, which drives the full load: perform_preload(), the C# assembly/UI build, then perform_postload(). This is the entry used for reloads; the initial Revit startup invokes the C# orchestrator directly.
Examples:
from pyrevit.loader.sessionmgr import load_session
load_session() # start loading a new pyRevit session
Returns:
| Type | Description |
|---|---|
str
|
session uuid |
Source code in pyrevitlib/pyrevit/loader/sessionmgr.py
reload_pyrevit()
find_all_commands(category_set=None, cache=True)
Source code in pyrevitlib/pyrevit/loader/sessionmgr.py
find_all_available_commands(use_current_context=True, cache=True)
find_pyrevitcmd(pyrevitcmd_unique_id)
Find a pyRevit command.
Searches the pyRevit-generated assemblies under current session for the command with the matching unique name (class name) and returns the command type. Notice that this returned value is a 'type' and should be instantiated before use.
Examples:
cmd = find_pyrevitcmd('pyrevitcore_pyrevit_pyrevit_tools_reload')
command_instance = cmd()
command_instance.Execute() # Provide commandData, message, elements
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pyrevitcmd_unique_id
|
str
|
Unique name for the command |
required |
Returns:
| Type | Description |
|---|---|
type
|
Type for the command with matching unique name |
Source code in pyrevitlib/pyrevit/loader/sessionmgr.py
create_tmp_commanddata()
Source code in pyrevitlib/pyrevit/loader/sessionmgr.py
execute_command_cls(extcmd_type, arguments=None, config_mode=False, exec_from_ui=True)
Source code in pyrevitlib/pyrevit/loader/sessionmgr.py
execute_command(pyrevitcmd_unique_id)
Executes a pyRevit command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pyrevitcmd_unique_id
|
str
|
Unique/Class Name of the pyRevit command |
required |