Skip to content

revit

Revit application wrapper.

Attributes

mlogger = get_logger(__name__) module-attribute

Classes

RevitWrapper()

Bases: ModuleType

Revit application wrapper.

Source code in pyrevitlib/pyrevit/revit/__init__.py
def __init__(self):
    pass

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

Source code in pyrevitlib/pyrevit/revit/__init__.py
@staticmethod
def open_doc(doc_path):
    """Open document at given path.

    Args:
        doc_path (str): document file path

    Returns:
        (DB.Document): opened document
    """
    return HOST_APP.app.OpenDocumentFile(doc_path)
close_doc(doc) staticmethod

Close given document.

Parameters:

Name Type Description Default
doc Document

document

required
Source code in pyrevitlib/pyrevit/revit/__init__.py
@staticmethod
def close_doc(doc):
    """Close given document.

    Args:
        doc (DB.Document): document
    """
    return doc.Close()
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
Source code in pyrevitlib/pyrevit/revit/__init__.py
@staticmethod
def post_command(command_id):
    """Request Revit to run a command.

    Args:
        command_id (str): command identifier e.g. ID_REVIT_SAVE_AS_TEMPLATE
    """
    HOST_APP.post_command(command_id)

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
def __init__(self, log_errors=True):
    self._fswallower = failure.FailureSwallower()
    self._logerror = log_errors

Functions

on_failure_processing(_, event_args)

Failure processing event handler.

Source code in pyrevitlib/pyrevit/revit/__init__.py
def on_failure_processing(self, _, event_args):
    """Failure processing event handler."""
    try:
        failure_accesssor = event_args.GetFailuresAccessor()
        mlogger.debug('request for failure processing...')
        result = event_args.GetProcessingResult()
        mlogger.debug('current failure processing result: %s', result)
        result = self._fswallower.preprocess_failures(failure_accesssor)
        mlogger.debug('setting failure processing results to: %s', result)
        event_args.SetProcessingResult(result)
    except Exception as fpex:
        mlogger.error('Error occured while processing failures. | %s', fpex)
get_swallowed_errors()

Return swallowed errors.

Source code in pyrevitlib/pyrevit/revit/__init__.py
def get_swallowed_errors(self):
    """Return swallowed errors."""
    return self._fswallower.get_swallowed_failures()
reset()

Reset swallowed errors.

Source code in pyrevitlib/pyrevit/revit/__init__.py
def reset(self):
    """Reset swallowed errors."""
    self._fswallower.reset()

Functions

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.

Source code in pyrevitlib/pyrevit/revit/__init__.py
def get_imported_symbol(symbol_name):
    """Geth an imported symbol by its name.

    Args:
        symbol_name (str): symbol name

    Returns:
        (Any): imported symbol, if found, None otherwise.
    """
    return globals().get(symbol_name, None)