revit
Revit application wrapper.
Attributes
mlogger = get_logger(__name__)
module-attribute
Classes
BaseWrapper(obj=None)
Bases: object
Base revit databse object wrapper.
Source code in pyrevitlib/pyrevit/revit/db/__init__.py
Functions
unwrap()
compare_attr(src, dest, attr_name, case_sensitive=False)
staticmethod
Source code in pyrevitlib/pyrevit/revit/db/__init__.py
compare_attrs(src, dest, attr_names, case_sensitive=False)
staticmethod
ElementWrapper(element)
Bases: BaseWrapper
Revit element wrapper.
Source code in pyrevitlib/pyrevit/revit/db/__init__.py
Attributes
assoc_doc
property
name
property
symbol_name
property
family_name
property
id
property
unique_id
property
workset_id
property
mark
property
location
property
x
property
y
property
z
property
Functions
unwrap()
compare_attr(src, dest, attr_name, case_sensitive=False)
staticmethod
Source code in pyrevitlib/pyrevit/revit/db/__init__.py
compare_attrs(src, dest, attr_names, case_sensitive=False)
staticmethod
get_param(param_name)
ExternalRef(link, extref)
Bases: ElementWrapper
External reference wraper.
Source code in pyrevitlib/pyrevit/revit/db/__init__.py
Attributes
assoc_doc
property
symbol_name
property
family_name
property
id
property
unique_id
property
workset_id
property
mark
property
location
property
x
property
y
property
z
property
name
property
link
property
linktype
property
path
property
Functions
unwrap()
compare_attr(src, dest, attr_name, case_sensitive=False)
staticmethod
Source code in pyrevitlib/pyrevit/revit/db/__init__.py
compare_attrs(src, dest, attr_names, case_sensitive=False)
staticmethod
get_param(param_name)
safe_get_param(param_name, default=None)
ProjectParameter(param_def, param_binding=None, param_ext_def=False)
Bases: BaseWrapper
Project parameter wrapper.
Source code in pyrevitlib/pyrevit/revit/db/__init__.py
Attributes
param_def = param_def
instance-attribute
param_binding = param_binding
instance-attribute
param_binding_type = self._determine_binding_type()
instance-attribute
shared = False
instance-attribute
param_ext_def = None
instance-attribute
param_guid = ''
instance-attribute
name = self.param_def.Name
instance-attribute
param_id = getattr(self.param_def, 'Id', None)
instance-attribute
unit_type = self.param_def.GetSpecTypeId()
instance-attribute
param_type = self.param_def.ParameterType
instance-attribute
param_group = self.param_def.ParameterGroup
instance-attribute
Functions
unwrap()
compare_attr(src, dest, attr_name, case_sensitive=False)
staticmethod
Source code in pyrevitlib/pyrevit/revit/db/__init__.py
compare_attrs(src, dest, attr_names, case_sensitive=False)
staticmethod
ProjectInfo(doc)
Bases: BaseWrapper
Project information.
Source code in pyrevitlib/pyrevit/revit/db/__init__.py
Attributes
name
property
number
property
address
property
author
property
building_name
property
client_name
property
issue_date
property
org_name
property
org_desc
property
status
property
location
property
path
property
filename
property
Functions
unwrap()
compare_attr(src, dest, attr_name, case_sensitive=False)
staticmethod
Source code in pyrevitlib/pyrevit/revit/db/__init__.py
compare_attrs(src, dest, attr_names, case_sensitive=False)
staticmethod
XYZPoint(obj=None)
Bases: BaseWrapper
Wrapper for XYZ point.
Source code in pyrevitlib/pyrevit/revit/db/__init__.py
Attributes
x
property
y
property
z
property
Functions
unwrap()
compare_attr(src, dest, attr_name, case_sensitive=False)
staticmethod
Source code in pyrevitlib/pyrevit/revit/db/__init__.py
compare_attrs(src, dest, attr_names, case_sensitive=False)
staticmethod
Transaction(name=None, doc=None, clear_after_rollback=False, show_error_dialog=False, swallow_errors=False, log_errors=True, nested=False)
Adds a context manager around Revit Transaction object.
Runs Transaction.Start() and Transaction.Commit()
before and after the context.
Automatically rolls back if exception is raised.
```python with Transaction('Move Wall'): wall.DoSomething()
with Transaction('Move Wall', doc, clear_after_rollback=False, show_error_dialog=False, swallow_errors=False, log_errors=True, nested=False) as action:
wall.DoSomething()
assert action.status == ActionStatus.Started # True
assert action.status == ActionStatus.Committed # True
```
Source code in pyrevitlib/pyrevit/revit/db/transaction.py
Attributes
name
property
writable
status
property
Functions
has_started()
DryTransaction(name=None, doc=None, clear_after_rollback=False, show_error_dialog=False, swallow_errors=False, log_errors=True, nested=False)
Bases: Transaction
Wrapper to a transaction that doesn't commit anything (dry-run).
Source code in pyrevitlib/pyrevit/revit/db/transaction.py
Attributes
name
property
writable
status
property
Functions
has_started()
TransactionGroup(name=None, doc=None, assimilate=True, log_errors=True)
Transactions group with context manager.
Source code in pyrevitlib/pyrevit/revit/db/transaction.py
Attributes
assimilate = assimilate
instance-attribute
name
property
writable
status
property
Functions
has_started()
RevitWrapper()
Bases: ModuleType
Revit application wrapper.
Attributes
uidoc
property
Active UI Document.
doc
property
Active document.
docs
property
Active documents.
active_view
property
writable
Active view.
active_ui_view
property
Active UI view.
servers
property
Available revit server names.
Functions
open_doc(doc_path)
staticmethod
Open document at given path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc_path
|
str
|
document file path |
required |
Returns:
| Type | Description |
|---|---|
Document
|
opened document |
close_doc(doc)
staticmethod
post_command(command_id)
staticmethod
Request Revit to run a command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command_id
|
str
|
command identifier e.g. ID_REVIT_SAVE_AS_TEMPLATE |
required |
ErrorSwallower(log_errors=True)
Suppresses warnings during script execution.
Examples:
with ErrorSwallower() as swallower:
for fam in families:
revit.doc.EditFamily(fam)
if swallower.get_swallowed():
logger.warn("Warnings swallowed")
Source code in pyrevitlib/pyrevit/revit/__init__.py
Functions
on_failure_processing(_, event_args)
Failure processing event handler.
Source code in pyrevitlib/pyrevit/revit/__init__.py
get_swallowed_errors()
Functions
get_parameter_data_type(definition)
Get parameter data type with version compatibility.
Safely retrieves parameter data type, handling both old (ParameterType) and new (GetDataType) API versions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
definition
|
Parameter definition object (InternalDefinition, ExternalDefinition, SharedParameterDefinition, etc.) |
required |
Returns:
| Type | Description |
|---|---|
|
ForgeTypeId for Revit 2022+, ParameterType enum for older versions, |
|
|
or None on error |
Source code in pyrevitlib/pyrevit/revit/db/__init__.py
is_yesno_parameter(definition)
Check if parameter is Yes/No (boolean) type.
Version-aware check for Yes/No parameters using appropriate API (SpecTypeId.Boolean.YesNo for 2022+, ParameterType.YesNo for older).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
definition
|
Parameter definition object |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
True if parameter is Yes/No type, False otherwise |
Source code in pyrevitlib/pyrevit/revit/db/__init__.py
carryout(name, doc=None)
Transaction Decorator.
Decorate any function with @doc.carryout('Txn name')
and the funciton will run within an Transaction context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the Transaction |
required |
doc
|
Document
|
Revit document |
None
|
@doc.carryout('Do Something')
def set_some_parameter(wall, value):
wall.parameters['Comments'].value = value
set_some_parameter(wall, value)
Source code in pyrevitlib/pyrevit/revit/db/transaction.py
serialize(api_object)
Source code in pyrevitlib/pyrevit/revit/db/pickling.py
deserialize(python_object)
Source code in pyrevitlib/pyrevit/revit/db/pickling.py
get_journals_folder()
get_current_journal_file()
get_current_session_id()
Source code in pyrevitlib/pyrevit/revit/journals.py
pick_element(message='')
Asks the user to pick an element.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
An optional message to display. |
''
|
Returns:
| Type | Description |
|---|---|
Element
|
element selected by the user. |
Source code in pyrevitlib/pyrevit/revit/selection.py
pick_element_by_category(cat_name_or_builtin, message='')
Returns the element of the specified category picked by the user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cat_name_or_builtin
|
str
|
name or built-in category of the element to pick. |
required |
message
|
str
|
message to display on selection. Defaults to ''. |
''
|
Returns:
| Type | Description |
|---|---|
Element
|
picked element. |
Raises:
| Type | Description |
|---|---|
PyRevitException
|
If no category matches the specified name or builtin. |
Source code in pyrevitlib/pyrevit/revit/selection.py
pick_elementpoint(message='', world=False)
Returns the element point selected by the user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
message to display. Defaults to ''. |
''
|
world
|
bool
|
whether to use world coordinates. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
PointOnElement
|
The selected point. |
Source code in pyrevitlib/pyrevit/revit/selection.py
pick_edge(message='')
Returns the edge selected by the user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
message to display. Defaults to ''. |
''
|
Returns:
| Type | Description |
|---|---|
Edge
|
The selected edge. |
Source code in pyrevitlib/pyrevit/revit/selection.py
pick_face(message='')
Returns the face selected by the user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
message to display. Defaults to ''. |
''
|
Returns:
| Type | Description |
|---|---|
Face
|
The selected face. |
Source code in pyrevitlib/pyrevit/revit/selection.py
pick_linked(message='')
Returns the linked element selected by the user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
message to display. Defaults to ''. |
''
|
Returns:
| Type | Description |
|---|---|
LinkedElement
|
The selected linked element. |
Source code in pyrevitlib/pyrevit/revit/selection.py
pick_elements(message='')
Asks the user to pick multiple elements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
An optional message to display. |
''
|
Returns:
| Type | Description |
|---|---|
list[Element]
|
elements selected by the user. |
Source code in pyrevitlib/pyrevit/revit/selection.py
pick_elements_by_category(cat_name_or_builtin, message='')
Returns the elements of the specified category picked by the user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cat_name_or_builtin
|
str
|
name or built-in category of the elements to pick. |
required |
message
|
str
|
message to display on selection. Defaults to ''. |
''
|
Returns:
| Type | Description |
|---|---|
list[Element]
|
picked elements. |
Raises:
| Type | Description |
|---|---|
PyRevitException
|
If no category matches the specified name or builtin. |
Source code in pyrevitlib/pyrevit/revit/selection.py
get_picked_elements(message='')
Allows the user to pick multple elements, one at a time.
It keeps asking the user to pick an element until no elements are selected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
The message to display. Defaults to ''. |
''
|
Yields:
| Type | Description |
|---|---|
Element
|
selected element |
Source code in pyrevitlib/pyrevit/revit/selection.py
get_picked_elements_by_category(cat_name_or_builtin, message='')
Pick elements by category.
Keeps asking the user to pick an element until no elements are selected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cat_name_or_builtin
|
str
|
category name or built-in category. |
required |
message
|
str
|
message to display while picking elements. |
''
|
Yields:
| Type | Description |
|---|---|
Element
|
The picked elements from the specified category. |
Source code in pyrevitlib/pyrevit/revit/selection.py
pick_elementpoints(message='', world=False)
Selects element points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
The message to display when selecting element points. |
''
|
world
|
bool
|
Select points in world coordinates. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
list[PointOnElement]
|
selected element points. |
Source code in pyrevitlib/pyrevit/revit/selection.py
pick_edges(message='')
Selects edges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
The message to display when selecting edges. |
''
|
Returns:
| Type | Description |
|---|---|
list[Edge]
|
selected edges. |
Source code in pyrevitlib/pyrevit/revit/selection.py
pick_faces(message='')
Selects faces.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
The message to display when selecting the faces. |
''
|
Returns:
| Type | Description |
|---|---|
list[Face]
|
selected faces. |
Source code in pyrevitlib/pyrevit/revit/selection.py
pick_linkeds(message='')
Selects linked elements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
The message to display when selecting linked elements. |
''
|
Returns:
| Type | Description |
|---|---|
list[LinkedElement]
|
selected linked elements. |
Source code in pyrevitlib/pyrevit/revit/selection.py
pick_point(message='')
Pick a point from the user interface.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
A message to display when prompting for the point. |
''
|
Returns:
| Type | Description |
|---|---|
tuple or None
|
A tuple representing the picked point as (x, y, z) coordinates, or None if no point was picked or an error occurred. |
Side Effects
If the active view does not have a SketchPlane assigned, this
function will automatically create a temporary work plane (aligned with the
active view) and assign it to the view before prompting for the point.
The work plane is removed after picking to avoid modifying the document.
Source code in pyrevitlib/pyrevit/revit/selection.py
pick_rectangle(message='', pick_filter=None)
Picks elements from the user interface by specifying a rectangular area.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
A custom message to display when prompting the user to pick elements. Default is an empty string. |
''
|
pick_filter
|
object
|
An object specifying the filter to apply when picking elements. Default is None. |
None
|
Returns:
| Type | Description |
|---|---|
list[ElementId]
|
The selected elements. |
Source code in pyrevitlib/pyrevit/revit/selection.py
get_selection_category_set()
Returns a CategorySet with the categories of the selected elements.
Returns:
| Type | Description |
|---|---|
CategorySet
|
categories of the selected elements. |
Source code in pyrevitlib/pyrevit/revit/selection.py
get_selection()
Returns the current selected items.
Returns:
| Type | Description |
|---|---|
ElementSelection
|
the current selected items |
get_imported_symbol(symbol_name)
Geth an imported symbol by its name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol_name
|
str
|
symbol name |
required |
Returns:
| Type | Description |
|---|---|
Any
|
imported symbol, if found, None otherwise. |