pyrevit

pyRevit root level config for all pyrevit sub-modules.

Examples

>>> from pyrevit import DB, UI
>>> from pyrevit import PyRevitException, PyRevitIOError
>>> # pyrevit module has global instance of the
>>> # _HostAppPostableCommand and _ExecutorParams classes already created
>>> # import and use them like below
>>> from pyrevit import HOST_APP
>>> from pyrevit import EXEC_PARAMS
class pyrevit.PyRevitException

Common base class for all pyRevit exceptions.

Parameters args and message are derived from Exception class.

class pyrevit.PyRevitIOError

Common base class for all pyRevit io-related exceptions.

class pyrevit._HostAppPostableCommand(name, key, id, rvtobj)

Private namedtuple for passing information about a PostableCommand

name

Postable command name

Type:str
key

Postable command key string

Type:str
id

Postable command id

Type:int
rvtobj

Postable command Id Object

Type:RevitCommandId
class pyrevit._HostApplication

Private Wrapper for Current Instance of Revit.

Provides version info and comparison functionality, alongside providing info on the active screen, active document and ui-document, available postable commands, and other functionality.

Parameters:host_uiapp (UIApplication) – Instance of running host.

Example

>>> hostapp = _HostApplication()
>>> hostapp.is_newer_than(2017)
active_view

Return view that is active (UIDocument.ActiveView).

addin_id

Return active addin id.

app

Return Application provided to the running command.

available_servers

Return list of available Revit server names.

build

Return build number (e.g. ‘20170927_1515(x64)’).

Type:str
doc

Return active Document.

docs

Return list of open Document objects.

get_postable_commands()

Return list of postable commands.

Returns:list of _HostAppPostableCommand
has_api_context

Determine if host application is in API context

is_demo

Determine if product is using demo license.

Type:bool
is_exactly(version)

bool: Return True if host app is equal to provided version.

Parameters:version (str or int) – version to check against.
is_newer_than(version, or_equal=False)

bool: Return True if host app is newer than provided version.

Parameters:version (str or int) – version to check against.
is_older_than(version)

bool: Return True if host app is older than provided version.

Parameters:version (str or int) – version to check against.
language

Return language type (e.g. ‘LanguageType.English_USA’).

Type:str
post_command(command_id)

Request Revit to run a command

Parameters:command_id (str) – command identifier e.g. ID_REVIT_SAVE_AS_TEMPLATE
pretty_name

Pretty name of the host (e.g. ‘Autodesk Revit 2019.2 build: 20190808_0900(x64)’)

Type:str
proc

Return current process object.

Type:System.Diagnostics.Process
proc_id

Return current process id.

Type:int
proc_name

Return current process name.

Type:str
proc_path

Return file path for the current process main module.

Type:str
proc_screen

Return handle to screen hosting current process.

Type:intptr
proc_screen_scalefactor

Return scaling for screen hosting current process.

Type:float
proc_screen_workarea

Return screen working area.

Type:System.Drawing.Rectangle
proc_window

Return handle to current process window.

Type:intptr
serial_no

Return serial number number (e.g. ‘569-09704828’).

Type:str
subversion

Return subversion number (e.g. ‘2018.3’).

Type:str
uiapp

Return UIApplication provided to the running command.

uidoc

Return active UIDocument.

username

Return the username from Revit API (Application.Username).

Type:str
version

Return version number (e.g. ‘2018’).

Type:str
version_name

Return version name (e.g. ‘Autodesk Revit 2018’).

Type:str
class pyrevit._ExecutorParams

Private Wrapper that provides runtime environment info.

cached_engine

Check whether pyrevit is running on a cached engine.

Type:bool
command_bundle

Return current command bundle name.

Type:str
command_config_path

Return current command config script path.

Type:str
command_controlid

Return current command control id.

Type:str
command_data

Return current command data.

Type:ExternalCommandData
command_elements

Return elements passed to by Revit.

Type:DB.ElementSet
command_extension

Return current command extension name.

Type:str
command_mode

Check if pyrevit is running in pyrevit command context.

Type:bool
command_name

Return current command name.

Type:str
command_path

Return current command path.

Type:str
command_uibutton

Return current command ui button.

Type:str
command_uniqueid

Return current command unique id.

Type:str
config_mode

Check if command is in config mode.

Type:bool
debug_mode

Check if command is in debug mode.

Type:bool
doc_mode

Check if pyrevit is running by doc generator.

Type:bool
engine_cfgs

Return ScriptRuntime.ScriptRuntimeConfigs

engine_id

Return engine id

engine_ver

Return PyRevitLoader.ScriptExecutor hardcoded version.

Type:str
event_args

Return event arguments object.

Type:DB.RevitAPIEventArgs
event_doc

Return document set in event args if available.

Type:DB.Document
event_sender

Return event sender object.

Type:Object
exec_id

Return execution unique id

exec_timestamp

Return execution timestamp

executed_from_ui

Check if command was executed from ui.

Type:bool
first_load

Check whether pyrevit is not running in pyrevit command.

Type:bool
needs_clean_engine

Check if command needs a clean IronPython engine.

Type:bool
needs_fullframe_engine

Check if command needs a full-frame IronPython engine.

Type:bool
needs_persistent_engine

Check if command needs a persistent IronPython engine.

Type:bool
needs_refreshed_engine

Check if command needs a newly refreshed IronPython engine.

Type:bool
output_stream

Return ScriptIO

result_dict

Return results dict for logging.

Type:Dictionary<String, String>
script_data

Return ScriptRuntime.ScriptData

script_runtime

Return command.

Type:PyRevitLabs.PyRevit.Runtime.ScriptRuntime
script_runtime_cfgs

Return ScriptRuntime.ScriptRuntimeConfigs

window_handle

Return output window. handle

Type:PyRevitLabs.PyRevit.Runtime.ScriptConsole