Looking for efficiency: Filter elements that have parameter that has value

Looking for efficiency: Filter elements that have parameter that has value

dante.van.wettum
Advocate Advocate
412 Views
1 Reply
Message 1 of 2

Looking for efficiency: Filter elements that have parameter that has value

dante.van.wettum
Advocate
Advocate

 

 

 

ElementParameterFilter fil = new ElementParameterFilter(ParameterFilterRuleFactory.CreateSharedParameterApplicableRule("SomeParameter"));
            FilteredElementCollector elements = new FilteredElementCollector(m_CommandData.Application.ActiveUIDocument.Document).WherePasses(fil).WhereElementIsNotElementType();

 

 

 

so first im using the ParameterFilterRuleFactory to get an collection of all elements that contain a certain parameter by name "SomeParameter".

EDIT: for clarification; at this point it is a project parameter im searching, therefore i used the string of the parameter and not the ID

 

Now in the next step i am looking for a way that is performance wise the best solution to filter all those elements that actually have any value assigned to that parameter.

 

I could just iterate over all elements in the collector by foreach element and check if the parameter is empty and so on and so forth, but i doubt if this would be verry efficient for big revit models tot contain a lot of elements where most of them wont have an value assigned.

 

i was wondering if there is a more efficient way to do this.

e.g. could i somehow already cast some check within the filteredelementcollector to already get rid of all elements that dont have a value assigned within the given parameter ?

 

 

 

EDIT:

As usual having a short break and writing this topic brings insight and new ideas... already fixing it before the first answer 😉

 

in case anyone was looking for it:

i ended up combining the ParameterValueProvider  (FilterStringGreater) with the ParameterFilterRuleFactory and made them into a LogicalAndFilter as an combined result.

 

now i get only the elements that have the parameter AND have a value assigned to them

413 Views
1 Reply
Reply (1)
Message 2 of 2

jeremytammik
Autodesk
Autodesk

Whatever you do, a parameter filter will be most efficient for retrieving data based on parameter values:

 

https://www.google.com/search?q=parameterfilter&as_sitesearch=thebuildingcoder.typepad.com

 

The Building Coder samples include several use case examples and implementations.

  



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

0 Likes