Getting FilterRule of ParameterFilterElement with API2020(c#)

Anonymous

Getting FilterRule of ParameterFilterElement with API2020(c#)

Anonymous
Not applicable

Hi,

I am trying to get a List of FilterRules from my ParameterFilterElement. I tried it with the API2028 and 2019 and it was pretty simple. I just had to use GetRules(). But since this doesn't exist in 2020 I can't find an alternative.

 

My code(c#) until now was:

 

 

foreach (ParameterFilterElement pfe in allFilter)
{

IList<FilterRule> rules = pfe.GetRules();

foreach (FilterRule rule in rules)
{...}

}

 

 

 

Is there an alternative to this?

I am a beginner so please excuse me if I am missing something obvious.

0 Likes
Reply
1,478 Views
3 Replies
Replies (3)

RPTHOMAS108
Mentor
Mentor

You have to go back to the 'What's New' section of the Revit 2019 API for a functionality description of this since .GetRules was deprecated in 2019 and removed in 2020:

 

ParameterFilterElement.GetRules

Replaced by:

ParameterFilterElement.GetElementFilter

Notes:

"The new function returns an ElementFilter representing the combination of filter rules used by the ParameterFilterElement. Note that logical combinations using both AND and OR operations are possible. GetRules() is applicable only to filters with rules conjoined with a single AND operation."

 

So you may have used this in 2019 but that would not have fully represented the feature subsequent to its update in the UI.

Anonymous
Not applicable

Thanks for the reply. I got the part about the old command being removed, but the new command doesn't solve my problem. My goal is to print every rule as text inside a textbox. Earlier I was able to convert every rule one by one to text, but now it is all in one ElementFilter object.

0 Likes

Anonymous
Not applicable

What has changed is that there is now an additional layer in between representing the two possibilities of 'AND' and 'OR' FilterSets.

 

so your previous 

rules = pfe.GetRules();

 

would have to change in order to first get the filters contained within, then you can loop over them

ElementLogicalFilter elf = pfe.GetElementFilter() as ElementLogicalFilter;
IList<ElementFilter> efs = elf.GetFilters();

rules = new List<FilterRule>();
foreach (ElementFilter ef in efs){
    ElementParameterFilter epf = ef as ElementParameterFilter;
    rules.AddRange(epf.GetRules());
}

 

0 Likes