def __init__(self, **filters): """ Args: **filters (``keyword args``): Scope and filters Returns: Collector (:any:`Collector`): Collector Instance Scope Options: * ``view`` `(DB.View)`: View Scope (Optional) * ``element_ids`` `([ElementId])`: List of Element Ids to limit Collector Scope * ``elements`` `([Element])`: List of Elements to limit Collector Scope Warning: Only one scope filter should be used per query. If more then one is used, only one will be applied, in this order ``view`` > ``elements`` > ``element_ids`` Filter Options: * is_type (``bool``): Same as ``WhereElementIsElementType`` * is_not_type (``bool``): Same as ``WhereElementIsNotElementType`` * of_class (``Type``): Same as ``OfClass``. Type can be ``DB.SomeType`` or string: ``DB.Wall`` or ``'Wall'`` * of_category (``BuiltInCategory``): Same as ``OfCategory``. Can be ``DB.BuiltInCategory.OST_Wall`` or ``'Wall'`` * owner_view (``DB.ElementId, View`): ``WhereElementIsViewIndependent(True)`` * is_view_independent (``bool``): ``WhereElementIsViewIndependent(True)`` * family (``DB.ElementId``, ``DB.Element``): Element or ElementId of Family * symbol (``DB.ElementId``, ``DB.Element``): Element or ElementId of Symbol * level (``DB.Level``, ``DB.ElementId``, ``Level Name``): Level, ElementId of Level, or Level Name * not_level (``DB.Level``, ``DB.ElementId``, ``Level Name``): Level, ElementId of Level, or Level Name * parameter_filter (:any:`ParameterFilter`): Applies ``ElementParameterFilter`` * exclude (`element_references`): Element(s) or ElementId(s) to exlude from result * and_collector (``collector``): Collector to intersect with. Elements must be present in both * or_collector (``collector``): Collector to Union with. Elements must be present on of the two. * where (`function`): function to test your elements against """ # Define Filtered Element Collector Scope + Doc collector_doc = filters.pop('doc') if 'doc' in filters else revit.doc if 'view' in filters: view = filters.pop('view') view_id = view if isinstance(view, DB.ElementId) else view.Id collector = DB.FilteredElementCollector(collector_doc, view_id) elif 'elements' in filters: elements = filters.pop('elements') element_ids = to_element_ids(elements) collector = DB.FilteredElementCollector(collector_doc, List[DB.ElementId](element_ids)) elif 'element_ids' in filters: element_ids = filters.pop('element_ids') collector = DB.FilteredElementCollector(collector_doc, List[DB.ElementId](element_ids)) else: collector = DB.FilteredElementCollector(collector_doc) super(Collector, self).__init__(collector) for key in filters.keys(): if key not in [f.keyword for f in FilterClasses.get_sorted()]: raise RpwException('Filter not valid: {}'.format(key)) self._collector = self._collect(collector_doc, collector, filters)
def __init__(self, **filters): """ Args: **filters (``keyword args``): Scope and filters Returns: Collector (:any:`Collector`): Collector Instance Scope Options: * ``view`` `(DB.View)`: View Scope (Optional) * ``element_ids`` `([ElementId])`: List of Element Ids to limit Collector Scope * ``elements`` `([Element])`: List of Elements to limit Collector Scope Warning: Only one scope filter should be used per query. If more then one is used, only one will be applied, in this order ``view`` > ``elements`` > ``element_ids`` Filter Options: * ``is_type`` (``bool``): Same as ``WhereElementIsElementType`` * ``is_not_type`` (``bool``): Same as ``WhereElementIsNotElementType`` * ``of_class`` (``Type``): Same as ``OfClass``. Type can be ``DB.SomeType`` or string: ``DB.Wall`` or ``'Wall'`` * ``of_category`` (``BuiltInCategory``): Same as ``OfCategory``. Can be ``DB.BuiltInCategory.OST_Wall`` or ``'Wall'`` * ``owner_view`` (``DB.ElementId, View`): ``WhereElementIsViewIndependent(True)`` * ``is_view_independent`` (``bool``): ``WhereElementIsViewIndependent(True)`` * ``family`` (``DB.ElementId``, ``DB.Element``)`: Element or ElementId of Family * ``symbol`` (``DB.ElementId``, ``DB.Element``)`: Element or ElementId of Symbol * ``level`` (``DB.Level``, ``DB.ElementId``, ``Level Name``)`: Level, ElementId of Level, or Level Name * ``not_level`` (``DB.Level``, ``DB.ElementId``, ``Level Name``)`: Level, ElementId of Level, or Level Name * ``parameter_filter`` (:any:`ParameterFilter`): Similar to ``ElementParameterFilter`` Class * ``where`` (`function`): function to test your elements against """ # Define Filtered Element Collector Scope + Doc collector_doc = filters.pop('doc') if 'doc' in filters else revit.doc if 'view' in filters: view = filters.pop('view') view_id = view if isinstance(view, DB.ElementId) else view.Id collector = DB.FilteredElementCollector(collector_doc, view_id) elif 'elements' in filters: elements = filters.pop('elements') element_ids = to_element_ids(elements) collector = DB.FilteredElementCollector(collector_doc,List[DB.ElementId](element_ids)) elif 'element_ids' in filters: element_ids = filters.pop('element_ids') collector = DB.FilteredElementCollector(collector_doc, List[DB.ElementId](element_ids)) else: collector = DB.FilteredElementCollector(collector_doc) super(Collector, self).__init__(collector) for key in filters.keys(): if key not in [f.keyword for f in FilterClasses.get_sorted()]: raise RpwException('Filter not valid: {}'.format(key)) self._collector = self._collect(collector_doc, collector, filters)
def add(self, elements_or_ids): """ Adds elements or element_ids to set. Handles single or list Args: element_reference (`DB.Element`, DB.Element_ids): Iterable Optional """ element_ids = to_element_ids(elements_or_ids) for eid in element_ids: self._elements[eid] = self.doc.GetElement(eid)
def add(self, elements_or_ids): """ Adds elements or element_ids to set. Handles single or list Args: element_reference (`DB.Element`, DB.Element_ids): Iterable Optional """ element_ids = to_element_ids(elements_or_ids) for id_ in element_ids: if id_ not in self._element_id_set: self._element_id_set.append(id_)
def from_list(element_references, doc=None): """ Instantiate Elements from a list of DB.Element instances Args: elements (``[DB.Element, DB.ElementId]``): List of element references Returns: (``list``): List of ``rpw.db.Element`` instances """ doc = doc or revit.doc try: return [Element(e) for e in element_references] except RpwTypeError: pass try: element_ids = to_element_ids(element_references) return [Element.from_id(id_, doc=doc) for id_ in element_ids] except RpwTypeError: raise
def __init__(self, **filters): """ Args: **filters (``keyword args``): Scope and filters Returns: Collector (:any:`Collector`): Collector Instance Scope Options: * ``view`` `(DB.View)`: View Scope (Optional) * ``element_ids`` `([ElementId])`: List of Element Ids to limit Collector Scope * ``elements`` `([Element])`: List of Elements to limit Collector Scope Warning: Only one scope filter should be used per query. If more then one is used, only one will be applied, in this order ``view`` > ``elements`` > ``element_ids`` Filter Options: * ``is_not_type`` (``bool``): Same as ``WhereElementIsNotElementType`` * ``is_type`` (``bool``): Same as ``WhereElementIsElementType`` * ``of_class`` (``Type``): Same as ``OfClass``. Type can be ``DB.SomeType`` or string: ``DB.Wall`` or ``'Wall'`` * ``of_category`` (``BuiltInCategory``): Same as ``OfCategory``. Type can be Enum member or String: ``DB.BuiltInCategory.OST_Wall`` or ``OST_Wall`` * ``is_view_independent`` (``bool``): ``WhereElementIsViewIndependent(True)`` * ``symbol`` (``DB.ElementId``, ``DB.Element``)`: Element or ElementId of Symbol * ``parameter_filter`` (:any:`ParameterFilter`): Similar to ``ElementParameterFilter`` Class """ # Pick Scope Filter, Default is doc if 'view' in filters: view = filters['view'] view_id = view if isinstance(view, DB.ElementId) else view.Id collector = DB.FilteredElementCollector(doc, view_id) filters.pop('view') elif 'view_id' in filters: view_id = filters['view_id'] collector = DB.FilteredElementCollector(doc, view_id) filters.pop('view_id') elif 'elements' in filters: elements = filters['elements'] element_ids = to_element_ids(elements) collector = DB.FilteredElementCollector(doc, List[DB.ElementId](element_ids)) filters.pop('elements') elif 'element_ids' in filters: element_ids = filters['element_ids'] collector = DB.FilteredElementCollector(doc, List[DB.ElementId](element_ids)) filters.pop('element_ids') else: collector = DB.FilteredElementCollector(doc) super(Collector, self).__init__(collector) self.elements = [] for key in filters.keys(): if key not in _Filter.MAP: raise RPW_Exception('Collector Filter not valid: {}'.format(key)) # Stores filters for chained calls self._filters = filters # Instantiates Filter class on attribute filter self.filter = _Filter(self) # Allows Class to Excecute on Construction, if filters are present. if filters: self.filter(**filters) # Call