DB.FilterStringRule on a AsValueString() Fails

268 views Asked by At

I am trying to create a pyrevit addin which filters elements in current view based on user selected element's parameter value. This works fine for parameters of string and double kind. But AsValueString() fails in DB.FilterStringRule probably because unit information is got lost in conversion of AsValueString type to string type in python. I have included the relevant code below:

target_parameter_value = ele.Parameter[target_parameter].AsValueString()# As value strings got converted to strings
param_id = DB.ElementId(target_parameter)
param_prov = DB.ParameterValueProvider(param_id)
param_equality = DB.FilterStringEquals() # equality class for string
value_rule = DB.FilterStringRule(param_prov,param_equality,target_parameter_value ,True)
param_filter = DB.ElementParameterFilter(value_rule)
    
elements = DB.FilteredElementCollector(doc)\
           .OfCategory(target_category)\
           .WhereElementIsNotElementType()\
           .WherePasses(param_filter)\
           .ToElementIds() # select category based on the rule

Is there any work around for AsValueString to work with DB.FilterStringRule or is there completely other rule for AsValueString like DB.FilterAsValueStringRule?

1

There are 1 answers

0
Jeremy Tammik On BEST ANSWER

You cannot use AsValueString with FilterStringRule at all. The latter interacts with the raw Revit database values. The former converts the raw Revit database value to a user visible display string. Please use the Parameter value accessors to read the raw database values instead: