def filter_rule(para, param_equality, value): param_id = DB.ElementId(para) param_prov = DB.ParameterValueProvider(param_id) value_rule = DB.FilterDoubleRule(param_prov, param_equality(), value, 1e-3 / 0.3048) # tolerance of 1 mm param_filter = DB.ElementParameterFilter(value_rule) return param_filter
def find_ins_wall(width): # which parameter to look at parameter_value_provider = DB.ParameterValueProvider( DB.ElementId(DB.BuiltInParameter.WALL_ATTR_WIDTH_PARAM)) # construct filter rule width_rule = DB.FilterDoubleRule(parameter_value_provider, DB.FilterNumericEquals(), width, 10e-10) # using slow parameter filter width_filter = DB.ElementParameterFilter(width_rule) # filter wall types of same width as insulation layer width_wall_types = DB.FilteredElementCollector(revit.doc) \ .OfCategory(DB.BuiltInCategory.OST_Walls) \ .WhereElementIsElementType() \ .WherePasses(width_filter) \ .ToElements() # iterate through wall types to find one that have one layer of insulation for wt in width_wall_types: compound_str = wt.GetCompoundStructure() num = compound_str.LayerCount if num == 1 and str(compound_str.GetLayerFunction(0)) == "Insulation": return wt
doc = __revit__.ActiveUIDocument.Document uidoc = __revit__.ActiveUIDocument curview = doc.ActiveView # gets current view if isinstance(curview, DB.ViewSheet): forms.alert("You're on a Sheet. Activate a model view please.", exitscript=True) length_feet = float(forms.ask_for_string( "Enter length in meters")) / 0.3048 # sometimes revit interprets 1 > 1.0 target_parameter = DB.BuiltInParameter.CURVE_ELEM_LENGTH # FAMILY_TOP_LEVEL_PARAM, FAMILY_BASE_LEVEL_PARAM param_id = DB.ElementId(target_parameter) param_prov = DB.ParameterValueProvider(param_id) param_equality = DB.FilterNumericEquals() # equality class value_rule = DB.FilterDoubleRule(param_prov, param_equality, length_feet, 1e-3 / 0.3048) # tolerance of 1 mm param_filter = DB.ElementParameterFilter(value_rule) same_cat_elements = \ DB.FilteredElementCollector(doc,curview.Id)\ .OfCategory(DB.BuiltInCategory.OST_Walls)\ .WhereElementIsNotElementType()\ .WherePasses(param_filter)\ .ToElements() filered_elements = [] for sim_element in same_cat_elements: r_type = sim_element.GetTypeId() # if r_type == type_id: # for same family type filered_elements.append(sim_element.Id)
category_id = ele.Category.Id type_id = ele.GetTypeId() if category_name == "Walls": cparam = ele.Parameter[DB.BuiltInParameter.WALL_USER_HEIGHT_PARAM] cparam = cparam.AsDouble()*.3048 target_parameter = DB.BuiltInParameter.WALL_USER_HEIGHT_PARAM # FAMILY_TOP_LEVEL_PARAM, FAMILY_BASE_LEVEL_PARAM else: cparam = ele.Parameter[DB.BuiltInParameter.INSTANCE_LENGTH_PARAM] cparam = cparam.AsDouble()*.3048 target_parameter = DB.BuiltInParameter.INSTANCE_LENGTH_PARAM # FAMILY_TOP_LEVEL_PARAM, FAMILY_BASE_LEVEL_PARAM param_id = DB.ElementId(target_parameter) param_prov = DB.ParameterValueProvider(param_id) param_equality = DB.FilterNumericEquals() # equality class value_rule = DB.FilterDoubleRule(param_prov,param_equality,cparam/0.3048 ,0.5) # 0.5 will give us a tolerance of 304.8 mm param_filter = DB.ElementParameterFilter(value_rule) same_cat_elements = \ DB.FilteredElementCollector(revit.doc, curview.Id)\ .OfCategoryId(category_id)\ .WhereElementIsNotElementType()\ .WherePasses(param_filter)\ .ToElements() filered_elements = [] for sim_element in same_cat_elements: r_type = sim_element.GetTypeId() if r_type == type_id: filered_elements.append(sim_element.Id)
def create_param_value_filter(filter_name, param_id, param_values, evaluator, match_any=True, case_sensitive=False, exclude=False, category_list=None, doc=None): doc = doc or DOCS.doc if HOST_APP.is_newer_than(2019, or_equal=True): rules = None else: rules = framework.List[DB.FilterRule]() param_prov = DB.ParameterValueProvider(param_id) # decide how to combine the rules logical_merge = \ DB.LogicalOrFilter if match_any else DB.LogicalAndFilter # create the rule set for pvalue in param_values: # grab the evaluator param_eval = PARAM_VALUE_EVALUATORS.get(evaluator, None) if not param_eval: raise PyRevitException("Unknown evaluator") # if value is str, eval is expected to be str str_eval, num_eval = param_eval if isinstance(pvalue, str): rule = DB.FilterStringRule(param_prov, str_eval(), pvalue, case_sensitive) # if num_eval is for str, e.g. "contains", or "startswith" # convert numeric values to str elif isinstance(num_eval, DB.FilterStringRuleEvaluator): if isinstance(pvalue, (int, float)): rule = DB.FilterStringRule(param_prov, num_eval(), str(pvalue), False) elif isinstance(pvalue, DB.ElementId): rule = DB.FilterStringRule(param_prov, num_eval(), str(pvalue.IntegerValue), False) # if value is int, eval is expected to be numeric elif isinstance(pvalue, int): rule = DB.FilterIntegerRule(param_prov, num_eval(), pvalue) # if value is float, eval is expected to be numeric elif isinstance(pvalue, float): rule = DB.FilterDoubleRule(param_prov, num_eval(), pvalue, sys.float_info.epsilon) # if value is element id, eval is expected to be numeric elif isinstance(pvalue, DB.ElementId): rule = DB.FilterElementIdRule(param_prov, num_eval(), pvalue) if exclude: rule = DB.FilterInverseRule(rule) if HOST_APP.is_newer_than(2019, or_equal=True): if rules: rules = logical_merge(rules, DB.ElementParameterFilter(rule)) else: rules = DB.ElementParameterFilter(rule) else: rules.Add(rule) # collect applicable categories if category_list: category_set = query.get_category_set(category_list, doc=doc) else: category_set = query.get_all_category_set(doc=doc) # filter the applicable categories filter_cats = [] for cat in category_set: if DB.ParameterFilterElement.AllRuleParametersApplicable( doc, framework.List[DB.ElementId]([cat.Id]), rules): filter_cats.append(cat.Id) # create filter return DB.ParameterFilterElement.Create( doc, filter_name, framework.List[DB.ElementId](filter_cats), rules)