Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Getting FilterRule of ParameterFilterElement with API2020(c#)

3 REPLIES 3
Reply
Message 1 of 4
Anonymous
1477 Views, 3 Replies

Getting FilterRule of ParameterFilterElement with API2020(c#)

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.

Labels (3)
3 REPLIES 3
Message 2 of 4
RPTHOMAS108
in reply to: Anonymous

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.

Message 3 of 4
Anonymous
in reply to: RPTHOMAS108

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.

Message 4 of 4
Anonymous
in reply to: Anonymous

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());
}

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report