def create_param_from_definition( param_def, category_list, builtin_param_group, type_param=False, allow_vary_betwen_groups=False, #pylint: disable=unused-argument doc=None): doc = doc or DOCS.doc # verify and create category set if category_list: category_set = query.get_category_set(category_list, doc=doc) else: category_set = query.get_all_category_set(doc=doc) if not category_set: raise PyRevitException('Can not create category set.') # create binding if type_param: new_binding = \ HOST_APP.app.Create.NewTypeBinding(category_set) else: new_binding = \ HOST_APP.app.Create.NewInstanceBinding(category_set) # FIXME: set allow_vary_betwen_groups # param_def.SetAllowVaryBetweenGroups(doc, allow_vary_betwen_groups) # insert the binding doc.ParameterBindings.Insert(param_def, new_binding, builtin_param_group) return True
def create_shared_param( param_id_or_name, category_list, builtin_param_group, type_param=False, allow_vary_betwen_groups=False, #pylint: disable=W0613 doc=None): doc = doc or HOST_APP.doc msp_list = query.get_defined_sharedparams() param_def = None for msp in msp_list: if msp == param_id_or_name: param_def = msp.param_def if not param_def: raise PyRevitException('Can not find shared parameter.') if category_list: category_set = query.get_category_set(category_list, doc=doc) else: category_set = query.get_all_category_set(doc=doc) if not category_set: raise PyRevitException('Can not create category set.') if type_param: new_binding = \ HOST_APP.app.Create.NewTypeBinding(category_set) else: new_binding = \ HOST_APP.app.Create.NewInstanceBinding(category_set) doc.ParameterBindings.Insert(param_def, new_binding, builtin_param_group) return True
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)