ParameterFilterElement 2020

ParameterFilterElement 2020

BrentBurgess1980
Collaborator Collaborator
1,843 Views
4 Replies
Message 1 of 5

ParameterFilterElement 2020

BrentBurgess1980
Collaborator
Collaborator

Hi All,

 

I am trying to filter rebar and apply a colour to it depending on it's size.  I have noticed that ParameterFilterElement is removed from 2020.

 

I have having some issues with creating the filter.

  public void CreateFilter(Document doc, View view, double barDiameter)
            {
            // create list of categories that will for the filter
            IList<ElementId> categories = new List<ElementId>();
            categories.Add(new ElementId(BuiltInCategory.OST_Rebar));

            // create a list of rules for the filter
            IList<FilterRule> rules = new List<FilterRule>();
            // This filter will have a single rule for the filter
            Parameter rebarSize = new FilteredElementCollector(doc).OfClass(typeof(Rebar)).FirstElement().get_Parameter(BuiltInParameter.REBAR_BAR_DIAMETER);
            rules.Add(ParameterFilterRuleFactory.CreateLessRule(rebarSize.Id, barDiameter, 0.1));
            
            ParameterFilterElement filter = null;
            using (Transaction t = new Transaction(doc, "Create and Apply Filter"))
                {
                t.Start();
                

                filter = ParameterFilterElement.Create(doc, "Thin Wall Filter", categories,rules);
                
                view.AddFilter(filter.Id);
                t.Commit();
                }

            string filterNames = "";
            foreach (ElementId id in view.GetFilters())
                {
                filterNames += doc.GetElement(id).Name + "\n";
                }
    
            OverrideGraphicSettings ogs = new OverrideGraphicSettings();
            ogs.SetCutLineColor(new Color((byte)255, (byte)0, (byte)0));
            //ogs.SetCutLineColor(getColour(doc.Application,12));

            using (Transaction t = new Transaction(doc, "Set Override Appearance"))
                {
                t.Start();
                view.SetFilterOverrides(filter.Id, ogs);
                t.Commit();
                }
            }

I think I have the rest of it correct, but can't test unitl I fix the ParameterFilterElement issue.

 

Can anyone point me in the right direction on how to do this?

 

Thanks,

 

Brent

Accepted solutions (1)
1,844 Views
4 Replies
Replies (4)
Message 2 of 5

jeremytammik
Autodesk
Autodesk

No, ParameterFilterElement has not been removed in Revit 2020.

 

What is the problem you see?

  



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 5

BrentBurgess1980
Collaborator
Collaborator

Hi @jeremytammik ... Yeah.... The wording wasn't the best on that post.

 

filter = ParameterFilterElement.Create(doc, "Thin Wall Filter", categories,rules);

 

The above line was the line that was causing issues. It flags an error saying it is obsolete in 2019 and removed in 2020.

 

I was looking for the new way to set the filters and havent had much luck.

 

I have been programming in AutoCAD for 15 years, and this is my first foray into the Revit space, so still trying to get my head around it all.

 

Thanks 

Brent

 

 

 

 

 

 

 

 

 

 

 

0 Likes
Message 4 of 5

sragan
Collaborator
Collaborator
Accepted solution

I got it to run by adding a few lines of code, and changing "rules" to "elemFilter" in the filter line of code.  Like this:

 

 

// create a list of rules for the filter
            IList<FilterRule> rules = new List<FilterRule>();
            // This filter will have a single rule for the filter
            Parameter rebarSize = new FilteredElementCollector(doc).OfClass(typeof(Rebar)).FirstElement().get_Parameter(BuiltInParameter.REBAR_BAR_DIAMETER);
            rules.Add(ParameterFilterRuleFactory.CreateLessRule(rebarSize.Id, barDiameter, 0.1));
            List<ElementFilter> elemFilters = new List<ElementFilter>();
					foreach (FilterRule filterRule in rules)
					{
    					ElementParameterFilter elemParamFilter = new ElementParameterFilter(filterRule);
    					elemFilters.Add(elemParamFilter);
					}
					
		 	LogicalAndFilter elemFilter = new LogicalAndFilter(elemFilters);
		 	
            ParameterFilterElement filter = null;
            using (Transaction t = new Transaction(doc, "Create and Apply Filter"))
                {
                t.Start();
                

                filter = ParameterFilterElement.Create(doc, "Thin Wall Filter", categories,elemFilter);

.....

 

Also, make sure you have a view open that shows rebar of the correct diameter.

 

0 Likes
Message 5 of 5

BrentBurgess1980
Collaborator
Collaborator

Thanks @sragan . That worked well!!

0 Likes