How to filter element which satisfy filter rule

How to filter element which satisfy filter rule

Anonymous
Not applicable
2,394 Views
9 Replies
Message 1 of 10

How to filter element which satisfy filter rule

Anonymous
Not applicable

Hello everyone,

 

I'm trying to get the family instances which satisfy a filter rule as shown in the image below.

So far I'm able to get the list of a category that has a specific filter name. But I'd like to get the family instances of those categories which satisfy the filter rule. I'm not sure how to do that via API. would appreciate any help thanks.

 

filter.PNG

 

 

 

 

 

 

0 Likes
Accepted solutions (1)
2,395 Views
9 Replies
Replies (9)
Message 2 of 10

FAIR59
Advisor
Advisor
Accepted solution

you can filter the document, first for the categories of the filter, and then foreach filterrule.

			ParameterFilterElement filter ;

			ElementMulticategoryFilter catfilter = new ElementMulticategoryFilter(filter.GetCategories());
			IEnumerable<Element> ElemsByFilter = new FilteredElementCollector(doc)
				.WhereElementIsNotElementType()
				.WherePasses(catfilter);
			foreach(FilterRule rule in filter.GetRules())
			{
				ElemsByFilter = ElemsByFilter.Where( e => rule.ElementPasses(e));
			}
Message 3 of 10

Anonymous
Not applicable

Thanks, it worked marvelously 🙂

0 Likes
Message 4 of 10

jeremytammik
Autodesk
Autodesk

Hi guys, @Anonymous and @FAIR59,

 

Thank you very much for the interesting question and answer.

 

I am sorry to say that I understand neither the one or the other.

 

Would you mind explaining the purpose of this to a pure programming nerd and Revit non-user?

 

I am completely mystified.

 

 

Thank you!

 

Cheers,

 

Jeremy

 

P.S. By the way, ParameterFilterElement.GetRules() is obsolete in Revit 2019 and can be replaced by GetElementFilter.

  



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 5 of 10

Anonymous
Not applicable

Hi @jeremytammik

 

Of course, I'd love to explain the question with pleasure. Let's say in Revit if someone needs to find all the walls on the Level 1 or a wall that has some thickness value xyz, they apply a filter rule and all the walls that satisfy a filter rule get highlighted. 

We needed this functionality in an add-in, so we could develop a BIM-Explorer for our Modelers to explore and navigate any element easily. The same idea was implemented by the ideatesoftware's addin called ideate explorer, see the video  for more information.

Please feel free to ask any question. 

 

Thank you,

Ali

0 Likes
Message 6 of 10

jeremytammik
Autodesk
Autodesk

Thank you @Anonymous!

 

That helps me understand the context.

 

The sample code provided by @FAIR59 highlights the solution very clearly on one hand, and confuses me on the other.

 

Can that be because it is purely for illustration purposes and makes little sense as it stands?

 

Cheers,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 7 of 10

Anonymous
Not applicable

@jeremytammik I think the following code will make sense to you.

 

 foreach (ParameterFilterElement pfe in new FilteredElementCollector(doc)
                .OfClass(typeof(ParameterFilterElement)).Cast<ParameterFilterElement>())
            {

               
                #region Get Filter Name, Category and Elements underlying the categories

                ParameterFilterElement filterElement = pfe;

                ElementMulticategoryFilter catfilter = new ElementMulticategoryFilter(filterElement.GetCategories());
                IEnumerable<Element> ElemsByFilter = new FilteredElementCollector(doc)
                    .WhereElementIsNotElementType()
                    .WherePasses(catfilter);
                foreach (FilterRule rule in filterElement.GetRules())
                {
                    ElemsByFilter = ElemsByFilter.Where(e => rule.ElementPasses(e));
                }

                #endregion

            }
0 Likes
Message 8 of 10

Anonymous
Not applicable
0 Likes
Message 9 of 10

jeremytammik
Autodesk
Autodesk

Many thanks, @Anonymous!

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 10 of 10

jeremytammik
Autodesk
Autodesk

Discussion and solution edited and preserved here for posterity:

 

http://thebuildingcoder.typepad.com/blog/2018/05/filterrule-use-and-retrieving-exterior-walls.html#9

 

Cheers,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder