transaction
Revit transactions facility.
Attributes
mlogger = get_logger(__name__)
module-attribute
DEFAULT_TRANSACTION_NAME = 'pyRevit Transaction'
module-attribute
Classes
Transaction(name=None, doc=None, clear_after_rollback=False, show_error_dialog=False, swallow_errors=False, log_errors=True, nested=False, failures_preprocessor=None)
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
```
Note
failures_preprocessor takes any DB.IFailuresPreprocessor and wins
over swallow_errors. Both are ignored when the transaction runs as a
SubTransaction inside an already open transaction.
Source code in pyrevitlib/pyrevit/revit/db/transaction.py
Attributes
name
property
writable
status
property
Methods:
has_started()
DryTransaction(name=None, doc=None, clear_after_rollback=False, show_error_dialog=False, swallow_errors=False, log_errors=True, nested=False, failures_preprocessor=None)
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
Methods:
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
Methods:
has_started()
DryTransactionGroup(name=None, doc=None, assimilate=True, log_errors=True)
Bases: TransactionGroup
Transaction group that always rolls back, even when its body succeeds.
Transactions inside it commit normally, so DocumentChanged fires and
their effects can be inspected, then the whole group is discarded.
Invariant
The document is left exactly as it was before the group started.
Source code in pyrevitlib/pyrevit/revit/db/transaction.py
Attributes
assimilate = assimilate
instance-attribute
name
property
writable
status
property
Methods:
has_started()
Functions:
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)