def recurse_change_filter(self, filter): """Рекурсивное изменение текстовых фильтров.""" if isinstance(filter, LogicalAndFilter): res = LogicalAndFilter( self.recurse_change_filter(filter.GetFilters())) return res elif isinstance(filter, LogicalOrFilter): res = LogicalOrFilter( self.recurse_change_filter(filter.GetFilters())) return res elif isinstance(filter, ElementParameterFilter): arr = List[FilterRule]() for i in filter.GetRules(): if isinstance(i, FilterInverseRule): i = i.GetInnerRule() cur_kit = self.cur_rule(i.RuleString) i.RuleString = cur_kit i = FilterInverseRule(i) if isinstance(i, FilterStringRule): cur_kit = self.cur_rule(i.RuleString) i.RuleString = cur_kit arr.Add(i) res = ElementParameterFilter(arr) return res elif isinstance(filter, List[ElementFilter]): arr = List[ElementFilter]() for i in filter: arr.Add(self.recurse_change_filter(i)) return arr
def categoryFilter(doc): categories = doc.Settings.Categories cats = [ElementCategoryFilter(c.Id) for c in categories if c.CategoryType == CategoryType.Model and c.CanAddSubcategory ] filter = None if len(cats): try: filter = LogicalOrFilter(List[ElementFilter](cats)) except Exception as ex: raise Exception(str(ex) + str(len(cats) )) return filter
def select(mode, uidoc=default_uidoc): """Run Super Select: all in model/view based on given mode.""" doc = uidoc.Document #>>>>>>>>>> FILTERS CONTAINER list_of_filters = List[ElementFilter]() #>>>>>>>>>> GET CURRENT SELECTION current_selection_ids = uidoc.Selection.GetElementIds() #>>>>>>>>>> LOOP THROUGH SELECTION for id in current_selection_ids: element = uidoc.Document.GetElement(id) #>>>>>>>>>> CREATE CATEGORY FILTER filter = create_filter( key_parameter=BuiltInParameter.ELEM_CATEGORY_PARAM, element_value=element.Category.Id) list_of_filters.Add(filter) if list_of_filters: #>>>>>>>>>> COMBINE FILTERS multiple_filters = LogicalOrFilter(list_of_filters) #>>>>>>>>>> GET ELEMENTS BASED ON SELECTION MODE if mode == "view": elems = FilteredElementCollector( doc, doc.ActiveView.Id).WherePasses( multiple_filters).ToElementIds() elif mode == "model": elems = FilteredElementCollector(doc).WherePasses( multiple_filters).ToElementIds() else: print("ERROR occured: 'wrong mode'.\n Please contact developer.") sys.exit() #>>>>>>>>>> SET SELECTION if elems: uidoc.Selection.SetElementIds(List[ElementId](elems))
pyRevit is a free set of scripts for Autodesk Revit: you can redistribute it and/or modify it under the terms of the GNU General Public License version 3, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. See this link for a copy of the GNU General Public License protecting this package. https://github.com/eirannejad/pyRevit/blob/master/LICENSE ''' __doc__ = 'Lists all Elements containing a Schema entity.' from Autodesk.Revit.DB import FilteredElementCollector, BuiltInCategory, ElementIsElementTypeFilter, LogicalOrFilter from Autodesk.Revit.DB.ExtensibleStorage import Schema uidoc = __revit__.ActiveUIDocument doc = __revit__.ActiveUIDocument.Document allElements = list(FilteredElementCollector(doc).WherePasses(LogicalOrFilter(ElementIsElementTypeFilter(False), ElementIsElementTypeFilter(True)))) guids = {sc.GUID.ToString():sc.SchemaName for sc in Schema.ListSchemas()} for el in allElements: schemaGUIDs = el.GetEntitySchemaGuids() for guid in schemaGUIDs: if guid.ToString() in guids.keys(): print('ELEMENT ID: {0}\t\tSCHEMA NAME: {1}'.format(el.Id.IntegerValue, guids[guid.ToString()])) print('Iteration completed over {0} elements.'.format(len(allElements)))
values = [] try: value = getTypeOrInstanceParameter(elem, BuiltInParameter.FURNITURE_WIDTH) * \ getTypeOrInstanceParameter(elem, BuiltInParameter.FAMILY_HEIGHT_PARAM) values.append(value) except: error.append(elem) return values door_cat = ElementCategoryFilter(BuiltInCategory.OST_Doors) win_cat = ElementCategoryFilter(BuiltInCategory.OST_Windows) room_col = FilteredElementCollector(doc).OfCategory( BuiltInCategory.OST_Rooms).ToElements() elements_col = FilteredElementCollector(doc).WherePasses(LogicalOrFilter(door_cat, win_cat)). \ WhereElementIsNotElementType().ToElements() phase = doc.Phases[1] elements = [] sum_square = [] TransactionManager.Instance.EnsureInTransaction(doc) for room in room_col: # param = room.LookupParameter('ПлощадьПроемов') elements_in_room = [] elem_square = [] for elem in elements_col: if elem.FromRoom[phase]:
if isinstance(line, ModelArc) or isinstance( line, ModelLine) or isinstance(line, DetailArc) or isinstance( line, DetailLine): return True return False for elId in uidoc.Selection.GetElementIds(): el = doc.GetElement(elId) if isline(el): print('Line ID: {0}'.format(el.Id)) print('Start:\t {0}'.format(el.GeometryCurve.GetEndPoint(0))) print('End:\t {0}\n'.format(el.GeometryCurve.GetEndPoint(1))) else: print('Elemend with ID: {0} is a not a line.\n'.format(el.Id)) elif selected_switch == 'Schema Entities': allElements = list( FilteredElementCollector(doc).WherePasses( LogicalOrFilter(ElementIsElementTypeFilter(False), ElementIsElementTypeFilter(True)))) guids = {sc.GUID.ToString(): sc.SchemaName for sc in Schema.ListSchemas()} for el in allElements: schemaGUIDs = el.GetEntitySchemaGuids() for guid in schemaGUIDs: if guid.ToString() in guids.keys(): print('ELEMENT ID: {0}\t\tSCHEMA NAME: {1}'.format( el.Id.IntegerValue, guids[guid.ToString()])) print('Iteration completed over {0} elements.'.format(len(allElements)))
new_rules = src_f_rules[line_no] rules_mod = True if new_rules != current_rules else False current_rules = new_rules if new_rules != current_rules else current_rules if name_mod: filt.Name = current_name status.append('n') if cats_mod: filt.SetCategories(List[ElementId](get_cats(current_cats))) status.append('c') if rules_mod or logic_mod: rules = get_rules(current_rules) if current_rules else [] epfilters = [ ElementParameterFilter(rule) for rule in rules ] # не протестирован и не проработан вариант создания фильтра без правил lfilter = LogicalAndFilter( epfilters) if current_logic == 'And' else LogicalOrFilter( epfilters) filt.SetElementFilter(lfilter) status.append('r') status = 'Mod ' + ', '.join(status) if status else '' data.append([ current_id, current_name, current_cats, current_logic, current_rules, status ]) if src_filters: all_filter_ids = [str(i.Id) for i in all_filters] for filter_id in src_f_ids: if filter_id not in all_filter_ids: line_no = src_f_ids.index(filter_id) filter_name = src_f_names[line_no]
def select(mode): """Run Super Select: all in model/view based on given mode.""" uidoc = __revit__.ActiveUIDocument doc = __revit__.ActiveUIDocument.Document # print(doc.Title) # FILTERS CONTAINER list_of_filters = List[ElementFilter]() # GET CURRENT SELECTION current_selection_ids = uidoc.Selection.GetElementIds() # LOOP THROUGH SELECTION for id in current_selection_ids: element = doc.GetElement(id) element_type = type(element) # [RULE] - LINES line_types = [ DetailLine, DetailCurve, DetailArc, DetailEllipse, DetailNurbSpline, ModelLine, ModelCurve, ModelArc, ModelEllipse, ModelNurbSpline ] if element_type in line_types: # [FILTER FOR CATEGORY] - RoomSeparation(-2000066) / AreaBoundary(-2000079) if element.Category.Id == ElementId( -2000066) or element.Category.Id == ElementId(-2000079): filter = create_filter( key_parameter=BuiltInParameter.ELEM_CATEGORY_PARAM, element_value=element.Category.Id) list_of_filters.Add(filter) # [FILTER FOR LINESTYLE] - Other Lines else: filter = create_filter( key_parameter=BuiltInParameter.BUILDING_CURVE_GSTYLE, element_value=element.LineStyle.Id) list_of_filters.Add(filter) # [RULE] - ReferencePlane elif element_type == ReferencePlane: filter = create_filter( key_parameter=BuiltInParameter.CLINE_SUBCATEGORY, element_value=element.get_Parameter( BuiltInParameter.CLINE_SUBCATEGORY).AsElementId()) list_of_filters.Add(filter) # [RULE] - PropertyLine elif element_type == PropertyLine: filter = create_filter( key_parameter=BuiltInParameter.ELEM_CATEGORY_PARAM, element_value=element.Category.Id) list_of_filters.Add(filter) # [RULE] - RevisionClouds elif element_type == RevisionCloud: filter = create_filter( key_parameter=BuiltInParameter.REVISION_CLOUD_REVISION, element_value=element.get_Parameter( BuiltInParameter.REVISION_CLOUD_REVISION).AsElementId()) list_of_filters.Add(filter) # [RULE] - ROOMS(-2000160) elif element.Category.Id == ElementId(-2000160): list_of_filters.Add( ElementCategoryFilter(BuiltInCategory.OST_Rooms)) # [RULE] - AREAS(-2003200) elif element.Category.Id == ElementId(-2003200): list_of_filters.Add( ElementCategoryFilter(BuiltInCategory.OST_Areas)) # [RULE] - ScopeBox(-2006000) elif element.Category.Id == ElementId(-2006000): filter = create_filter( key_parameter=BuiltInParameter.ELEM_CATEGORY_PARAM, element_value=element.Category.Id) list_of_filters.Add(filter) # [RULE] - PlanRegion(-2000191) elif element.Category.Id == ElementId(-2000191): filter = create_filter( key_parameter=BuiltInParameter.ELEM_CATEGORY_PARAM, element_value=element.Category.Id) list_of_filters.Add(filter) # [RULE] - MatchLine(-2000193) elif element.Category.Id == ElementId(-2000191): filter = create_filter( key_parameter=BuiltInParameter.ELEM_CATEGORY_PARAM, element_value=element.Category.Id) list_of_filters.Add(filter) # [RULE] - Others else: filter = create_filter( key_parameter=BuiltInParameter.ELEM_TYPE_PARAM, element_value=element.GetTypeId()) list_of_filters.Add(filter) if list_of_filters: # COMBINE FILTERS multiple_filters = LogicalOrFilter(list_of_filters) # GET ELEMENTS BASED ON SELECTION MODE if mode == "view": elems = FilteredElementCollector( doc, doc.ActiveView.Id).WherePasses( multiple_filters).ToElementIds() elif mode == "model": elems = FilteredElementCollector(doc).WherePasses( multiple_filters).ToElementIds() else: print("ERROR occured: 'wrong mode'.\n Please contact developer.") sys.exit() # SET SELECTION if elems: uidoc.Selection.SetElementIds(List[ElementId](elems))