简体   繁体   中英

DB.FilterStringRule on a AsValueString() Fails

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?

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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM