Hello,
I would like to create an application which automatically lists all possible ViewFilters for a given category.
E.g. for the category "walls" I would like to receive the parameters shown in the screenshot below.
It seems like these filters are combinations of Project Parameters, Type Parameters and Instance Parameters.
Is there any way to collect all parameters which are allewed for creating a filter rule? Or at least a way to check if a parameter is valid for creating a filter rule?
Thanks,
Sam
I'm working with Revit 2020
Solved! Go to Solution.
Solved by jeremy_tammik. Go to Solution.
Hi @samuel_kreuz,
You first can Iterate and filter elements from a document to match the category you need. The element filtering is performed by FilteredElementCollector instances which are instantiated for a given document. e. if you want to get wall category
FilteredElementCollector collector= new FilteredElementCollector(doc);
collector.OfCategory(BuiltInCategory.OST_Walls);
You then Process the collector results using foreach statements and LINQ queries applying your custom filters.
See details explained well in:
I could be wrong here - and someone is welcome to correct me - but I'm assuming that list is more or less going to be the same as the available shared parameters on an element of that category. What you could try doing is using a FilteredElementCollector to grab the first item of the category, Walls in your example, get all the parameters with, and then filter through the parameter list for parameters where .IsShared is true.
I asked the devteam for you. Maybe they can add to the very valid suggestions above. Thank you, @caroline.gitonga and @stewart.skyler !
I think the problem I am facing is that this filter rule parameter list does not only include shared and project parameters, but also some built-in parameters. As stewart.skyler and caroline.gitonga mentioned, I can loop through all shared parameters of a wall element and retreive only the shared ones.
When there are no shared parameters/project parameters defined, the list looks like this:
If I filter out one wall-type from the project and grab its non-shared parameters, the output looks like this:
You can see, it's not possible to filter for some parameters e.g. the "Coarse Scale Fill Color" parameter. So there are less parameters to filter than there are parameters available on the wall-type.
You can see that some paramters like "Area" and "Length" can not be found in the wall-type because they only make sense on an instanced object.
So if I filter after instances using "WhereElementIsNotElementType()" then the output is the following:
So my question might actually be, what are the rules for the built-in elements to be included into the View Filter Parameter list and is there a way to find out which ones those are?
Thanks 🙂
Edit: the code I used to create the above lists:
List<string> parametersShared = new List<string>();
List<string> parametersNotShared = new List<string>();
FilteredElementCollector col = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsNotElementType();
var wall = col.FirstElement();
var wallParams = wall.Parameters;
foreach(Parameter param in wallParams)
{
if (param.IsShared)
{
parametersShared.Add(param.Definition.Name + "\r\n");
}
else
{
parametersNotShared.Add(param.Definition.Name + "\r\n");
}
}
parametersShared.Sort();
parametersNotShared.Sort();
The development team suggests taking a look at the ParameterFilterUtilities class, specifically ParameterFilterUtilities.GetFilterableParametersInCommon:
https://www.revitapidocs.com/2022/7ea624c7-2c0d-c9bb-3b2c-1ac798cf6606.htm
Does that help?
Hey Jeremy,
this is exactly what I am looking for! I wasn't aware of the "ParameterFilterUtilities" until now.
They seem to have some really useful methods for working with ViewFilters.
This is how I checked for which parameters are valid if the selected category is "walls".
List<string> parameterNames = new List<string>();
IList<ElementId> wallCatList = new List<ElementId>() { new ElementId(BuiltInCategory.OST_Walls) };
StringBuilder sb = new StringBuilder();
var paramColl = ParameterFilterUtilities.GetFilterableParametersInCommon(doc, wallCatList);
foreach (ElementId param in paramColl)
{
BuiltInParameter bip = (BuiltInParameter)param.IntegerValue;
string label = LabelUtils.GetLabelFor(bip);
parameterNames.Add(label);
}
parameterNames.Sort();
parameterNames.ForEach(e => sb.Append(e + "\r\n"));
TaskDialog.Show("Filtered Parameters", sb.ToString());
And the result is includes all built-in parameters which can be used for filtering:
Thanks 👌