rpw.exceptions

Exceptions

Use these exceptions to try against specific Rpw Exceptions.

>>> from rpw.exceptions import RpwWrongStorageType
>>> try:
...     element.parameters['Height'].value = 'String'
... except RpwWrongStorageType:
...     print('Height Parameter cannot be a string')
...     raise

This module also provides easy access to the Autodesk.Revit.Exceptions namespaces:

>>> from rpw.exceptions import RevitExceptions
>>> try:
...     doc.Delete(ElementId)
... except RevitExceptions.InvalidObjectException:
...     print('This element is no longer valid ')
exception rpw.exceptions.RpwCoerceError(value, target_type)

Bases: rpw.exceptions.RpwException, exceptions.ValueError

Coerce Error

exception rpw.exceptions.RpwException

Bases: exceptions.Exception

Revit Python Wrapper Base Exception

exception rpw.exceptions.RpwParameterNotFound(element, param_name)

Bases: rpw.exceptions.RpwException, exceptions.KeyError

Revit Python Wrapper Parameter Error

exception rpw.exceptions.RpwTypeError(type_expected, type_received='not reported')

Bases: exceptions.TypeError

Revit Python Wrapper Type Exception

exception rpw.exceptions.RpwValueError(value_expected, value_received='not reported')

Bases: exceptions.ValueError

Revit Python Wrapper Value Error Exception

exception rpw.exceptions.RpwWrongStorageType(storage_type, value)

Bases: rpw.exceptions.RpwException, exceptions.TypeError

Wrong Storage Type


Implementation


from rpw.utils.logger import logger
from Autodesk.Revit import Exceptions as RevitExceptions


class RpwException(Exception):
    """ Revit Python Wrapper Base Exception """


class RpwTypeError(TypeError):
    """ Revit Python Wrapper Type Exception """
    def __init__(self, type_expected, type_received='not reported'):
        msg = 'expected [{}], got [{}]'.format(type_expected, type_received)
        super(RpwTypeError, self).__init__(msg)


class RpwValueError(ValueError):
    """ Revit Python Wrapper Value Error Exception """
    def __init__(self, value_expected, value_received='not reported'):
        msg = 'expected [{}], got [{}]'.format(value_expected, value_received)
        super(RpwValueError, self).__init__(msg)


class RpwParameterNotFound(RpwException, KeyError):
    """ Revit Python Wrapper Parameter Error """
    def __init__(self, element, param_name):
        msg = 'parameter not found [element:{}]:[param_name:{}]'.format(
                                                        element.Id, param_name)
        super(RpwParameterNotFound, self).__init__(msg)


class RpwWrongStorageType(RpwException, TypeError):
    """ Wrong Storage Type """
    def __init__(self, storage_type, value):
        msg = 'Wrong Storage Type: [{}]:[{}:{}]'.format(storage_type,
                                                        type(value), value)
        super(RpwWrongStorageType, self).__init__(msg)


class RpwCoerceError(RpwException, ValueError):
    """ Coerce Error """
    def __init__(self, value, target_type):
        msg = 'Could not cast value:{} to target_type:{}'.format(value,
                                                                 target_type)
        super(RpwCoerceError, self).__init__(msg)