Creating filter rules

Creating filter rules

ssw9UZNL
Advocate Advocate
4,228 Views
9 Replies
Message 1 of 10

Creating filter rules

ssw9UZNL
Advocate
Advocate

Hello,

 

I am having an issue setting filter rules. I am using the API docs as below

 

https://www.revitapidocs.com/2015/810b786e-afec-a383-ddda-21d1032d1b10.htm

 

Using python i can get everything besides the filter rules. I also believe that the process has changed in the API between 2019 and 2020 and there is limited documentation. 

 

public static ParameterFilterElement Create(
	Document aDocument,
	string name,
	ICollection<ElementId> categories,
	IList<FilterRule> rules
)

 

I managed to get to this, but it seems that the .create no longer takes this as the input

 

rule_01 = DB.ParameterFilterRuleFactory.CreateContainsRule(Parameter_ElementID, "Yes", False)
Rules_List.append(rule_01)
# Convert single FitlerRule to List<FilterRule>
rules = List[DB.FilterRule](Rules_List)

0 Likes
4,229 Views
9 Replies
Replies (9)
Message 2 of 10

RPTHOMAS108
Mentor
Mentor

Have a look at ParameterFilterElement.Create(Document, String, ICollection(ElementId), ElementFilter)

 

This has  long explanation in RevitAPI.chm, basically since rules can now be applied in 'or' and 'and' fashion the old way of using with just 'and' applied to list of FilterRules argument is no longer valid. You need to use a logical filter or ElementParameterFilter for ElementFilter argument.

 

ParameterFilterElement Class (revitapidocs.com)

 

The old way is similar to using ElementParameterFilter as ElementFilter argument above (with multiple filter rules). There isn't much difference in that respect to replicate the old way (just an extra layer of ElementParameterFilter). This doesn't take advantage of the full feature change however.

0 Likes
Message 3 of 10

architect.bim
Collaborator
Collaborator

Hi!

If you use Revit 2020 and higher you need to pass instance of ElementFilter. If you reed documentation of Create method for Revit API 2020 this process is explained there. This instance can be either ElementLogicalFilter of ElementParameterFilter.


Maxim Stepannikov | Architect, BIM Manager, Instructor
0 Likes
Message 4 of 10

ssw9UZNL
Advocate
Advocate

Ok- i

am still slightly lost- do you have any snall

extract examples handy where

i could view both options? Or links to where they are outlined in the api docs?

 

thankyou -

0 Likes
Message 5 of 10

architect.bim
Collaborator
Collaborator

Actually I am working right now on some king of script which creates filters. I can share piece of my Python code that creates appropriate ElementParameterFilter:

 

 

parameter_ids = {
    'mark': DB.ElementId(DB.BuiltInParameter.DOOR_NUMBER),
}

mark_ends_with_rule = DB.ParameterFilterRuleFactory.CreateEndsWithRule(
    parameter_ids['mark'],
    'D',
    False
)

mark_contains_rule = DB.ParameterFilterRuleFactory.CreateContainsRule(
    parameter_ids['mark'],
    '20 Minute Rated',
    False
)

rules = List[DB.FilterRule]()
rules.Add(mark_ends_with_rule)
rules.Add(mark_contains_rule)

element_filter = DB.ElementParameterFilter(rules)

 

 

 


Maxim Stepannikov | Architect, BIM Manager, Instructor
Message 6 of 10

ssw9UZNL
Advocate
Advocate

@architect.bim 

 

Firstly thanks for taking your time to explain this. 

 

This is excellent I will test this logic. So to understand this is an element parameter filter but you could also use the element logical filters?

 

is the disadvantage of using these rather than logicals is that you can choose between and or or within the rules?

 

and in the api docs under element filters- is this type one of the slow or quick filters?

0 Likes
Message 7 of 10

ssw9UZNL
Advocate
Advocate

One more thought- you are passing in two rules- would this work using the way you have done it or would you need to use the logical if you wanted to pass in two sets of rules? As it would need to know if it’s and or or...

and how would this then look.

 

again- Thankyou- it’s starting to make sense!

0 Likes
Message 8 of 10

architect.bim
Collaborator
Collaborator

If I am not mistaken logical filter is neither quick nor slow. Its speed depends on which filters it includes. But ElementParameterFilter is definitely slow. So in case of creating view filters logical filter should work as slow.

ElementLogicalFilter is used to create sets of rules and control whether this set is logical_or or logical_and:

 

 

rule_set_or = DB.LogicalOrFilter(
    DB.ElementParameterFilter(mark_ends_with_rule),
    DB.ElementParameterFilter(mark_contains_rule)
)

filters_and = List[DB.ElementFilter]()
filters_and.Add(DB.ElementParameterFilter(width_less_rule))
filters_and.Add(DB.ElementParameterFilter(height_greater_rule))
filters_and.Add(rule_set_or)

rule_set_and = DB.LogicalAndFilter(filters_and)

 

 

210218_2230_026.jpg


Maxim Stepannikov | Architect, BIM Manager, Instructor
Message 9 of 10

ssw9UZNL
Advocate
Advocate

Ok so when you have more than one rule,

you need to wrap the db. Element parameter filter within a logical filter in order to let two rules work?

 

and so what you have as element parameter or...

this is what you pass in as the element filter in order to create the filter?

0 Likes
Message 10 of 10

architect.bim
Collaborator
Collaborator

Logical filter combines several other element filters. In this case it can be either ElementParameterFilter (to create rule) or ElementLogicalFilter to create nested set of rules.

I think what you need now is to test the code by yourself and adapt it to your needs. Because all the necessary information to do it is in the code above. You won't completely understand it until you do it by yourself.

Good luck!


Maxim Stepannikov | Architect, BIM Manager, Instructor
0 Likes