Filter element by custom family parameter value

Filter element by custom family parameter value

longt61
Advocate Advocate
598 Views
3 Replies
Message 1 of 4

Filter element by custom family parameter value

longt61
Advocate
Advocate

I have a generic model family with custom parameters loaded into project, and I want to filter all of its instances whose family parameter is of certain value. Since Revit API provides us with ElementParameterFilter, I would  like to use it instead of checking the parameter value by.Net Linq for performance reason. However, I can't find a way to retrieve the custom family parameter Id. The closest thing to my desired solution is what I have found here:

Find family elements by name parameter 

I tried filtering ParameterElement, parameter definition, Builtin parameter ... without hope. I am wondering is this approach is even possible at all for Revit API 2021. If it is, how can I implement it?

Thanks in advance.

0 Likes
599 Views
3 Replies
Replies (3)
Message 2 of 4

jeremy_tammik
Alumni
Alumni

The post that you point to explains the situation for a built-in parameter.

  

For a custom parameter, you cannot use the built-in parameter enumeration. Instead, you can use the parameter Definition or Id to identify the custom parameter on the element.

 

You can see some filtering examples in The Building Coder topic group:

 

https://thebuildingcoder.typepad.com/blog/about-the-author.html#5.9

 

Many more are listed in The Building Coder samples in the module CmdCollectorPerformance.cs.

  

I think that for a custom parameter, the challenge might be to set up the correct ParameterValueProvider. For that, grab one instance of your elements, retrieve the parameter from that using its name, and grab the parameter id from that:

 

Element e = ...
Parameter p = e.get_Parameter("...");
ElementId pid = p.Id
ParameterValueProvider pvp = new ParameterValueProvider(parameter.Id);

 

Please let us know how it goes and share your final solution for others to see. Thank you!

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 4

longt61
Advocate
Advocate

Thanks for the quick reply, @jeremy_tammik .

Your post about ElementParameterFilter did a great help for one of my recent work on schedule editing. But I think it is quite different this time due to 2 factors:

1. The family parameter, is not a Builtin Parameter of courses, does not appear in project document ParameterElement list (as you can see in the picture below). Therefore, I can not get parameter Id By filtering all parameter element.

parameterElement.png

 

 

 

 

 

 

 

 

 

 

2. When I check the instance of my custom family in current project, the parameter of each instance has a different Id. So no getting Id from instance like my previous work.

parameterId.png

 

 

 

 

 

 

 

 

 

 

I can check the value of each family instance accepting the performance penalty, though. I think if Revit can make family parameter filterable with ElementParameterFilter can be a huge help with large project. I am not sure if my approach is available, or even possible at all, but I am still open for suggestions.

0 Likes
Message 4 of 4

jeremy_tammik
Alumni
Alumni

Hmm. Weird. Can you grab the Definition object for your custom parameter and use that for filtering? I am pretty sure that what you need is possible.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes