Hi @d.mihovXY79A ,
You can use the FilterCategoryRule. The class provides a filter rule that matches elements of a set of categories.
You could check out this article on How to use FilterCategoryRule .
FilterCategoryRule inserts the categories that are responsible for the filter, my goal is to change AllSelectedCategories to one specific one as I showed in the picture in the post. At the moment I do not find a way to do this.
I have the same problem.
If we have created a filter with more than one category, it will always be selected AllSelected Categories.
This only happens when i em using OR Condition.
public void CreateFilter()
{
UIDocument uidoc = this.ActiveUIDocument;
UIDocument activeUiDocument = this.ActiveUIDocument;
Document doc = activeUiDocument.Document;
UIApplication uiapp = new UIApplication(Application);
using(Transaction t = new Transaction(doc, "Filter testing"))
{
t.Start();
List<ElementId> categories = new List<ElementId>();
categories.Add(new ElementId(BuiltInCategory.OST_Roofs));
categories.Add(new ElementId(BuiltInCategory.OST_Walls));
List<FilterRule> filterRules_0 = new List<FilterRule>();
List<FilterRule> filterRules_1 = new List<FilterRule>();
filterRules_0.Add(ParameterFilterRuleFactory.CreateEqualsRule(new ElementId(BuiltInParameter.SYMBOL_NAME_PARAM), "Example", true));
List<ElementId> categoriesForRules = new List<ElementId>();
categoriesForRules.Add(new ElementId(BuiltInCategory.OST_Walls));
FilterCategoryRule filterCategoryRule = new FilterCategoryRule(categoriesForRules);
filterRules_1.Add(filterCategoryRule);
filterRules_1.Add(ParameterFilterRuleFactory.CreateEqualsRule(new ElementId(BuiltInParameter.SYMBOL_NAME_PARAM), "Test", true));
ElementParameterFilter currentFilter_0 = new ElementParameterFilter(filterRules_0);
ElementParameterFilter currentFilter_1 = new ElementParameterFilter(filterRules_1);
List<ElementFilter> elementsFilters = new List<ElementFilter>();
elementsFilters.Add(currentFilter_0);
elementsFilters.Add(currentFilter_1);
LogicalOrFilter logicalOrFilter = new LogicalOrFilter(elementsFilters);
ParameterFilterElement parameterFilterElement = ParameterFilterElement.Create(doc, "TestFilter", categories, logicalOrFilter);
doc.ActiveView.AddFilter(parameterFilterElement.Id);
doc.ActiveView.SetFilterVisibility(parameterFilterElement.Id, false);
t.Commit();
}
}
This is my solution for this issue. Of great importance is the sequence of adding FilterCategoryRule and FilterRule to the list of filter rules, if exchanged in the code as a sequence will not work.
The result: