Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get all possible FilterRule parameters

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
samuel_kreuz
1651 Views, 6 Replies

Get all possible FilterRule parameters

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.

FilterRules.jpg

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

Tags (1)
Labels (3)
6 REPLIES 6
Message 2 of 7

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:

 

Carol Gitonga, Developer Advocacy and Support, ADN Open
Message 3 of 7

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.

Message 4 of 7

I asked the devteam for you. Maybe they can add to the very valid suggestions above. Thank you, @caroline.gitonga  and @stewart.skyler ! 

  

Jeremy Tammik, Developer Advocacy and Support, The Building Coder, Autodesk Developer Network, ADN Open
Message 5 of 7
samuel_kreuz
in reply to: samuel_kreuz

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:

 

list_with_no_shared_params.jpg


If I filter out one wall-type from the project and grab its non-shared parameters, the output looks like this:

 

all_not_shared_parameters_types.jpg

 

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:

 

all_not_shared_parameters_instance.jpg

 

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();

 

 

Message 6 of 7

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?

 

Jeremy Tammik, Developer Advocacy and Support, The Building Coder, Autodesk Developer Network, ADN Open
Message 7 of 7
samuel_kreuz
in reply to: samuel_kreuz

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:

GetFilterableParameters.jpg

Thanks 👌

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community