Spatial Elements

Room Wrapper

class rpw.db.Room(element, doc=None)

Bases: rpw.db.element.Element

DB.Architecture.Room Wrapper Inherits from Element

>>> from rpw import db
>>> room = db.Room(SomeRoom)
<rpw:Room % DB.Architecture.Room | name:Office number:122>
>>> room.name
'Office'
>>> room.number
'122'
>>> room.is_placed
True
>>> room.is_bounded
True
Attribute:
_revit_object (DB.Architecture.Room): Wrapped DB.Architecture.Room
__init__(element, doc=None)

Main Element Instantiation

>>> from rpw import db
>>> wall = db.Element(SomeElementId)
<rpw: WallInstance % DB.Wall >
>>> wall.parameters['Height']
10.0
>>> wall.parameters.builtins['WALL_LOCATION_LINE']
1
Parameters:element (Element Reference) – Can be DB.Element, DB.ElementId, or int.
Returns:Instance of Wrapped Element.
Return type:Element
_category

Default Category Access Parameter. Overwrite on wrapper as needed. See Family Wrapper for an example.

category

Wrapped DB.Category

classmethod collect(**kwargs)

Collect all elements of the wrapper using the default collector. This method is defined on the main Element wrapper, but the collector parameters are defined in each wrapper. For example, WallType uses the _collector_params: {‘of_class’: DB.WallType, ‘is_type’: True}

These default collector parameters can be overriden by passing keyword args to the collectors call.

>>> from rpw import db
>>> wall_types_collector = db.WallType.collect()
<rpw:Collector % FilteredElementCollector [count:4]>
>>> wall_types_collector.get_elements()  # All Wall Types
[<rpw:WallType [name:Wall 1] [id:1557]>, ... ]
>>> wall_types_collector.get_elements()
[<rpw:Area % DB.Area | Rentable:30.2>]
>>> rooms = db.WallInstance.collect(level="Level 1")
[<rpw:WallInstance % DB.Wall symbol:Basic Wall>]
delete()

Deletes Element from Model

get_category(wrapped=True)

Wrapped DB.Category

is_bounded

bool for whether Room is Bounded. Uses result of Room.Area attribute to define if room is Bounded.

is_placed

bool for whether Room is Placed. Uses result of Room.Location attribute to define if room is Placed.

name

Room Name as parameter ValueROOM_NAME built-in parameter

number

Room Number as parameter ValueROOM_NUMBER built-in parameter

type

Get’s Element Type using the default GetTypeId() Method. For some Elements, this is the same as element.Symbol or wall.WallType

Parameters:doc (DB.Document, optional) – Document of Element [default: revit.doc]
Returns:Wrapped rpw.db.Element element type
Return type:(Element)
unwrap()

Returns the Original Wrapped Element

Area Wrapper

class rpw.db.Area(element, doc=None)

Bases: rpw.db.spatial_element.Room

DB.Area Wrapper Inherits from Room

>>> from rpw import db
>>> area = db.Area(SomeArea)
<rpw:Area % DB.Area | name:USF area: 100.0>
>>> area.name
'Rentable'
>>> area.is_placed
True
>>> area.is_bounded
True
Attribute:
_revit_object (DB.Area): Wrapped DB.Area
__init__(element, doc=None)

Main Element Instantiation

>>> from rpw import db
>>> wall = db.Element(SomeElementId)
<rpw: WallInstance % DB.Wall >
>>> wall.parameters['Height']
10.0
>>> wall.parameters.builtins['WALL_LOCATION_LINE']
1
Parameters:element (Element Reference) – Can be DB.Element, DB.ElementId, or int.
Returns:Instance of Wrapped Element.
Return type:Element
_category

Default Category Access Parameter. Overwrite on wrapper as needed. See Family Wrapper for an example.

area

Area – .Area attribute

category

Wrapped DB.Category

classmethod collect(**kwargs)

Collect all elements of the wrapper using the default collector. This method is defined on the main Element wrapper, but the collector parameters are defined in each wrapper. For example, WallType uses the _collector_params: {‘of_class’: DB.WallType, ‘is_type’: True}

These default collector parameters can be overriden by passing keyword args to the collectors call.

>>> from rpw import db
>>> wall_types_collector = db.WallType.collect()
<rpw:Collector % FilteredElementCollector [count:4]>
>>> wall_types_collector.get_elements()  # All Wall Types
[<rpw:WallType [name:Wall 1] [id:1557]>, ... ]
>>> wall_types_collector.get_elements()
[<rpw:Area % DB.Area | Rentable:30.2>]
>>> rooms = db.WallInstance.collect(level="Level 1")
[<rpw:WallInstance % DB.Wall symbol:Basic Wall>]
delete()

Deletes Element from Model

get_category(wrapped=True)

Wrapped DB.Category

is_bounded

bool for whether Room is Bounded. Uses result of Room.Area attribute to define if room is Bounded.

is_placed

bool for whether Room is Placed. Uses result of Room.Location attribute to define if room is Placed.

name

Area Scheme Name – Area attribute parameter

number

Room Number as parameter ValueROOM_NUMBER built-in parameter

scheme

Area Scheme – Wrapped Area Scheme

type

Get’s Element Type using the default GetTypeId() Method. For some Elements, this is the same as element.Symbol or wall.WallType

Parameters:doc (DB.Document, optional) – Document of Element [default: revit.doc]
Returns:Wrapped rpw.db.Element element type
Return type:(Element)
unwrap()

Returns the Original Wrapped Element

Area Scheme Wrapper

class rpw.db.AreaScheme(element, doc=None)

Bases: rpw.db.element.Element

DB.AreaScheme Wrapper Inherits from Element

>>> scheme = wrapped_area.scheme
<rwp:AreaScheme % DB.AreaScheme | name:USF>
>>> scheme.areas
[ < Autodesk.Revit.DB.Area>, ...]
>>> scheme.name
'USF'
Attribute:
_revit_object (DB.AreaScheme): Wrapped DB.AreaScheme
areas

Returns all Area Instances of this Area Scheme

name

Area Scheme Name – Area attribute parameter


Implementation


import rpw
from rpw import revit, DB
from rpw.db import Element
from rpw.utils.logger import logger
from rpw.db.builtins import BipEnum


class Room(Element):
    """
    `DB.Architecture.Room` Wrapper
    Inherits from :any:`Element`

    >>> from rpw import db
    >>> room = db.Room(SomeRoom)
    <rpw:Room % DB.Architecture.Room | name:Office number:122>
    >>> room.name
    'Office'
    >>> room.number
    '122'
    >>> room.is_placed
    True
    >>> room.is_bounded
    True

    Attribute:
        _revit_object (DB.Architecture.Room): Wrapped ``DB.Architecture.Room``
    """

    _revit_object_class = DB.Architecture.Room
    _revit_object_category = DB.BuiltInCategory.OST_Rooms
    _collector_params = {'of_category': _revit_object_category,
                         'is_not_type': True}

    @property
    def name(self):
        """ Room Name as parameter Value: ``ROOM_NAME`` built-in parameter"""
        # Note: For an unknown reason, roominstance.Name does not work on IPY
        return self.parameters.builtins['ROOM_NAME'].value

    @name.setter
    def name(self, value):
        self.parameters.builtins['ROOM_NAME'].value = value

    @property
    def number(self):
        """ Room Number as parameter Value: ``ROOM_NUMBER`` built-in parameter"""
        return self.parameters.builtins['ROOM_NUMBER'].value

    @number.setter
    def number(self, value):
        self.parameters.builtins['ROOM_NUMBER'].value = value

    # @property
    # def from_room(self, value):
        # TODO: from_room

    @property
    def is_placed(self):
        """ ``bool`` for whether Room is Placed.
        Uses result of ``Room.Location`` attribute to define if room is Placed.
        """
        return bool(self._revit_object.Location)

    @property
    def is_bounded(self):
        """ ``bool`` for whether Room is Bounded.
        Uses result of ``Room.Area`` attribute to define if room is Bounded.
        """
        return self._revit_object.Area > 0

    def __repr__(self):
        return super(Room, self).__repr__(data={'name': self.name,
                                                'number': self.number})


class Area(Room):
    """
    `DB.Area` Wrapper
    Inherits from :any:`Room`

    >>> from rpw import db
    >>> area = db.Area(SomeArea)
    <rpw:Area % DB.Area | name:USF area: 100.0>
    >>> area.name
    'Rentable'
    >>> area.is_placed
    True
    >>> area.is_bounded
    True

    Attribute:
        _revit_object (DB.Area): Wrapped ``DB.Area``
    """

    _revit_object_class = DB.Area
    _revit_object_category = DB.BuiltInCategory.OST_Areas
    _collector_params = {'of_category': _revit_object_category,
                         'is_not_type': True}

    @property
    def name(self):
        """ Area Scheme Name: Area attribute parameter"""
        return self.scheme.name

    @property
    def scheme(self):
        """ Area Scheme: Wrapped Area Scheme"""
        return AreaScheme(self._revit_object.AreaScheme)

    @property
    def area(self):
        """ Area: .Area attribute"""
        return self._revit_object.Area

    def __repr__(self):
        return super(Element, self).__repr__(data={'name': self.name,
                                                   'area': self.area})


class AreaScheme(Element):
    """
    `DB.AreaScheme` Wrapper
    Inherits from :any:`Element`

    >>> scheme = wrapped_area.scheme
    <rwp:AreaScheme % DB.AreaScheme | name:USF>
    >>> scheme.areas
    [ < Autodesk.Revit.DB.Area>, ...]
    >>> scheme.name
    'USF'

    Attribute:
        _revit_object (DB.AreaScheme): Wrapped ``DB.AreaScheme``
    """

    _revit_object_class = DB.AreaScheme
    _collector_params = {'of_class': _revit_object_class}

    @property
    def name(self):
        """ Area Scheme Name: Area attribute parameter"""
        return self._revit_object.Name

    @property
    def areas(self):
        """ Returns all Area Instances of this Area Scheme """
        bip = BipEnum.get_id('AREA_SCHEME_ID')
        param_filter = rpw.db.Collector.ParameterFilter(bip, equals=self._revit_object.Id)
        collector = rpw.db.Collector(parameter_filter=param_filter,
                                     **Area._collector_params)
        return collector.wrapped_elements

    def __repr__(self):
        return super(AreaScheme, self).__repr__(data={'name': self.name})