Family

Instance

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

Bases: rpw.db.element.Element, rpw.utils.mixins.CategoryMixin

DB.FamilyInstance Wrapper

>>> instance = rpw.db.Element(SomeFamilyInstance)
<rpw:FamilyInstance % DB.FamilyInstance | name:72" x 36">
>>> instance.get_symbol().name
'72" x 36"'
>>> instance.get_family()
<RPW_Family:desk>
>>> instance.get_siblings()
[<rpw:FamilyInstance % DB.FamilyInstance | name:72" x 36">, ... ]
Attribute:
_revit_object (DB.FamilyInstance): Wrapped DB.FamilyInstance
__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

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

family

Wrapped DB.Family of the DB.FamilyInstance

get_assembly

Returns

(bool, DB.Element) None if element not in Assembly, else
returns Element
get_category(wrapped=True)

Wrapped DB.Category

get_family(wrapped=True)

Wrapped DB.Family of the DB.FamilyInstance

get_siblings(wrapped=True)

Other DB.FamilyInstance of the same DB.FamilySymbol

get_symbol(wrapped=True)

DB.FamilySymbol of the DB.FamilyInstance

in_assembly

**Returns* – (bool)* – True if element is inside an AssemblyInstance

name

Name Property

siblings

Other DB.FamilyInstance of the same DB.FamilySymbol

symbol

Wrapped DB.FamilySymbol of the DB.FamilyInstance

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

Symbol

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

Bases: rpw.db.element.Element, rpw.utils.mixins.CategoryMixin

DB.FamilySymbol Wrapper

>>> symbol = rpw.db.Element(SomeSymbol)
<rpw:FamilySymbol % DB.FamilySymbol | name:72" x 36">
>>> instance.get_symbol().name
'72" x 36"'
>>> instance.family
<rpw:Family % DB.Family | name:desk>
>>> instance.siblings
<rpw:Family % DB.Family | name:desk>, ... ]
Attribute:
_revit_object (DB.FamilySymbol): Wrapped DB.FamilySymbol
__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

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

family

ReturnsFamily – Wrapped DB.Family of the symbol

get_category(wrapped=True)

Wrapped DB.Category

get_family(wrapped=True)
Returns:Wrapped DB.Family of the symbol
Return type:Family
get_instances(wrapped=True)
Returns:
List of model instances of
the symbol (unwrapped)
Return type:[DB.FamilyInstance]
get_siblings(wrapped=True)
Returns:
List of symbol Types
of the same Family (unwrapped)
Return type:[DB.FamilySymbol]
instances

Returns

[DB.FamilyInstance]: List of model instances
of the symbol (unwrapped)
name

Name Property

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

Family

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

Bases: rpw.db.element.Element, rpw.utils.mixins.CategoryMixin

DB.Family Wrapper

Attribute:
_revit_object (DB.Family): Wrapped DB.Family
__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

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

get_instances(wrapped=True)

Returns: [DB.FamilyInstance]: List of model instances in this family (unwrapped)

get_siblings(wrapped=True)

Returns: [DB.Family]: List of Family elements in the same category (unwrapped)

get_symbols(wrapped=True)

Returns: [DB.FamilySymbol]: List of Symbol Types in the family (unwrapped)

name

Name Property

siblings

Returns – [DB.Family] – List of Family elements in the same category (unwrapped)

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


Implementation


import rpw
from rpw import revit, DB
from rpw.db.element import Element
from rpw.base import BaseObjectWrapper
from rpw.exceptions import RpwException
from rpw.utils.logger import logger, deprecate_warning
from rpw.utils.mixins import CategoryMixin
from rpw.db.builtins import BicEnum
from rpw.db.category import Category


class FamilyInstance(Element, CategoryMixin):
    """
    `DB.FamilyInstance` Wrapper

    >>> instance = rpw.db.Element(SomeFamilyInstance)
    <rpw:FamilyInstance % DB.FamilyInstance | name:72" x 36">
    >>> instance.get_symbol().name
    '72" x 36"'
    >>> instance.get_family()
    <RPW_Family:desk>
    >>> instance.get_siblings()
    [<rpw:FamilyInstance % DB.FamilyInstance | name:72" x 36">, ... ]

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

    _revit_object_class = DB.FamilyInstance
    _collector_params = {'of_class': _revit_object_class, 'is_not_type': True}

    def get_symbol(self, wrapped=True):
        """ ``DB.FamilySymbol`` of the ``DB.FamilyInstance`` """
        symbol = self._revit_object.Symbol
        return FamilySymbol(symbol) if wrapped else symbol

    @property
    def symbol(self):
        """ Wrapped ``DB.FamilySymbol`` of the ``DB.FamilyInstance`` """
        deprecate_warning('FamilyInstance.symbol',
                          'FamilyInstance.get_symbol(wrapped=True)')
        return self.get_symbol(wrapped=True)

    def get_family(self, wrapped=True):
        """ Wrapped ``DB.Family`` of the ``DB.FamilyInstance`` """
        symbol = self.get_symbol()
        return symbol.get_family(wrapped=wrapped)

    @property
    def family(self):
        """ Wrapped ``DB.Family`` of the ``DB.FamilyInstance`` """
        deprecate_warning('FamilyInstance.family',
                          'FamilyInstance.get_family(wrapped=True)')
        return self.get_family(wrapped=True)

    def get_siblings(self, wrapped=True):
        """ Other ``DB.FamilyInstance`` of the same ``DB.FamilySymbol`` """
        symbol = self.get_symbol()
        return symbol.get_instances(wrapped=wrapped)

    @property
    def siblings(self):
        """ Other ``DB.FamilyInstance`` of the same ``DB.FamilySymbol`` """
        deprecate_warning('FamilyInstance.siblings',
                          'FamilyInstance.get_siblings(wrapped=True)')
        return self.get_siblings(wrapped=True)

    @property
    def in_assembly(self):
        """
        Returns:
            (bool): True if element is inside an AssemblyInstance
        """
        if self._revit_object.AssemblyInstanceId.IntegerValue == -1:
            return False
        else:
            return True

    @property
    def get_assembly(self, wrapped=True):
        """
        Returns:
            (bool, DB.Element) ``None`` if element not in Assembly, else
                returns Element
        """
        if self.in_assembly:
            assembly_id = self._revit_object.AssemblyInstanceId
            assembly = self.doc.GetElement()
            return  Element(assembly) if wrapped else assembly
        else:
            return None

    def __repr__(self):
        symbol_name = self.get_symbol(wrapped=True).name
        return super(FamilyInstance, self).__repr__(data={'symbol': symbol_name})


class FamilySymbol(Element, CategoryMixin):
    """
    `DB.FamilySymbol` Wrapper

    >>> symbol = rpw.db.Element(SomeSymbol)
    <rpw:FamilySymbol % DB.FamilySymbol | name:72" x 36">
    >>> instance.get_symbol().name
    '72" x 36"'
    >>> instance.family
    <rpw:Family % DB.Family | name:desk>
    >>> instance.siblings
    <rpw:Family % DB.Family | name:desk>, ... ]

    Attribute:
        _revit_object (DB.FamilySymbol): Wrapped ``DB.FamilySymbol``
    """
    _revit_object_class = DB.FamilySymbol
    _collector_params = {'of_class': _revit_object_class, 'is_type': True}

    def get_family(self, wrapped=True):
        """
        Returns:
            :any:`Family`: Wrapped ``DB.Family`` of the symbol

        """
        family = self._revit_object.Family
        return Family(family) if wrapped else family

    @property
    def family(self):
        """Returns:
            :any:`Family`: Wrapped ``DB.Family`` of the symbol """
        deprecate_warning('FamilySymbol.family',
                          'FamilySymbol.get_family(wrapped=True)')
        return self.get_family(wrapped=True)

    def get_instances(self, wrapped=True):
        """
        Returns:
            [``DB.FamilyInstance``]: List of model instances of
                the symbol (unwrapped)
        """
        collector = rpw.db.Collector(symbol=self._revit_object.Id, is_not_type=True)
        return collector.get_elements(wrapped)

    @property
    def instances(self):
        """
        Returns:
            [``DB.FamilyInstance``]: List of model instances
                of the symbol (unwrapped)
        """
        deprecate_warning('FamilySymbol.instances',
                          'FamilySymbol.get_instances(wrapped=True)')
        return self.get_instances(wrapped=True)

    def get_siblings(self, wrapped=True):
        """
        Returns:
            [``DB.FamilySymbol``]: List of symbol Types
                of the same Family (unwrapped)
        """
        symbols_ids = self._revit_object.GetSimilarTypes()
        return [self.doc.GetElement(i) for i in symbols_ids]
        # Same as: return self.family.symbols

    @property
    def siblings(self):
        deprecate_warning('FamilySymbol.siblings',
                          'FamilySymbol.get_siblings(wrapped=True)')
        return self.get_siblings(wrapped=True)


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


class Family(Element, CategoryMixin):
    """
    `DB.Family` Wrapper

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

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

    def get_instances(self, wrapped=True):
        """Returns:
            [``DB.FamilyInstance``]: List of model instances in this family (unwrapped)
        """
        # There has to be a better way
        instances = []
        for symbol in self.get_symbols(wrapped=True):
            symbol_instances = symbol.get_instances(wrapped=wrapped)
            instances.append(symbol_instances)
        return instances

    @property
    def instances(self):
        deprecate_warning('Family.instances',
                          'Family.get_instances(wrapped=True)')
        return self.get_instances(wrapped=True)

    def get_symbols(self, wrapped=True):
        """Returns:
            [``DB.FamilySymbol``]: List of Symbol Types in the family (unwrapped)
        """
        symbols_ids = self._revit_object.GetFamilySymbolIds()
        elements = [self.doc.GetElement(i) for i in symbols_ids]
        return [Element(e) for e in elements] if wrapped else elements

    @property
    def symbols(self):
        deprecate_warning('Family.symbols',
                          'Family.get_symbols(wrapped=True)')
        return self.get_symbols(wrapped=True)

    def get_siblings(self, wrapped=True):
        """Returns:
            [``DB.Family``]: List of Family elements in the same category (unwrapped)
        """
        return self.category.get_families(wrapped=wrapped)

    @property
    def siblings(self):
        """Returns:
            [``DB.Family``]: List of Family elements in the same category (unwrapped)
        """
        return self.get_siblings(wrapped=True)

    @property
    def _category(self):
        """Returns:
            :any:`Category`: Wrapped ``DB.Category`` of the Family """
        return self._revit_object.FamilyCategory

    def __repr__(self):
        return super(Family, self).__repr__({'name': self.name})