In this article, let us try to find some walls which have a specific project parameter and its value is in a certain range.
This time, the ElementParameterFilter or its partner ParameterValueProvider is totally out of question for this simple task. If not, then how to construct a ParameterValueProvider from a project parameter (bound shared parameter)?
Fortunately, the get_Parameter method of the Element class is very friendly, it accepts almost all possible ways to identity a parameter either native or custom. Here is the help method:
public static ICollection<ElementId> GetWallsWithProjectParameterInRange(RvtDocument doc)
{
List<ElementId> elems = new List<ElementId>();
foreach (Element e in new FilteredElementCollector(doc).OfClass(typeof(Wall)).ToElements())
{
Parameter param1 = e.get_Parameter("PrjParameter1");
if (param1 != null)
{
double value = param1.AsDouble();
if (value > 5 && value < 10)
elems.Add(e.Id);
}
}
return elems;
}
We do not even have to worry about all those provider, filter and rule stuffs. A couple of lines of code do it all. Here is the test code:
…
DateTime time = DateTime.Now;
ICollection<ElementId> elemIds = GetWallsWithProjectParameterInRange(CachedDoc);
TimeSpan timespan = DateTime.Now - time;
string message = string.Format("{0} elements are found in {1} milliseconds.", elemIds.Count, timespan.TotalMilliseconds);
MessageBox.Show(message);
…
Here is a sample output supposing two walls have the project parameter PrjParameter1 attached, the parameter type is integer, and their values are between 5 and 10 feet in the test model:
It is also very quick (around 15 milliseconds), isn’t it?
Not sure whether it would be quicker if some various parameter value providers, filter rules and evaluators regarding project parameters had been provided.
ElementParameterFilter Creator of RevitAddinCoder can help create code combining various existing filter rules and evaluators to filter element parameters.
Recent Comments