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: 

How can I change the Filter Rule Category to specific element category through the API 2020

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
d.mihovXY79A
979 Views, 4 Replies

How can I change the Filter Rule Category to specific element category through the API 2020

dmihovXY79A_0-1644910587016.png

 

4 REPLIES 4
Message 2 of 5

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 .

 

Carol Gitonga, Developer Advocacy and Support, ADN Open
Message 3 of 5
d.mihovXY79A
in reply to: d.mihovXY79A

Hi @caroline.gitonga 

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.

dmihovXY79A_0-1644917456164.png

 

Message 4 of 5
s.valkov
in reply to: d.mihovXY79A

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.

Message 5 of 5
d.mihovXY79A
in reply to: d.mihovXY79A

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:

Capture.PNG

Tags (1)

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

Post to forums  

Autodesk Customer Advisory Groups


Rail Community