i assume you cannot directly manipulate view filters for specific view like turn on/off, set override, etc. in 2014 and 2015? but you can do it through view template? this means you have to temporarily create/modify view template?
Solved! Go to Solution.
Not specific to the view, but you can create a custom view filter and then apply it to any view you like. I do this quite regularly, I'd advise creating a management framework for them to handle naming conflicts and the clean up of unused filters. If you need a few code snippets, let me know I'll get you started.
Here's some basic code that will generate a filter that matches for equality with a particular parameter value. It also checks for an existing filter with the same name and re-uses an existing one if found, this allows updating the rules of a filter without having to specifically update each affected view.
public ParameterFilterElement CreateViewFilter(Document dbDoc) { Parameter filterParam = someParameterFromSomewhere; ElementId paramId = filterParam.Id; List<ElementId> catIds = new List<ElementId>(); catIds.Add(new ElementId(BuiltInCategory.OST_GenericModel)); catIds.Add(new ElementId(BuiltInCategory.OST_Roofs)); catIds.Add(new ElementId(BuiltInCategory.OST_Walls)); List<FilterRule> filterRules = new List<FilterRule>(); filterRules.Add(ParameterFilterRuleFactory.CreateEqualsRule(paramId, "Desired Parameter Value", true)); ParameterFilterElement elemFilter = null; String filterName = "My New Filter"; // Search for existing filters with same name List<FilterElement> filterList = new FilteredElementCollector(dbDoc).WherePasses(new ElementClassFilter(typeof(FilterElement))).ToElements().Cast<FilterElement>().ToList() foreach(ParameterFilterElement filter in filterList) { if(filter.Name == filterName) // Filter Exists, update rules and use existing filter { elemFilter = filter; elemFilter.ClearRules(); elemFilter.SetRules(filterRules); break; } } if(elemFilter == null) // Doesn't Exist, create new filter { elemFilter = ParameterFilterElement.Create(dbDoc, filterName, catIds, filterRules); } return elemFilter; }
Now to apply this filter to a view you do something like this.
public void AddFilterToView(Document dbDoc, View viewToFilter) { ParameterFilterElement newFilter = CreateViewFilter(dbDoc); viewToFilter.AddFilter(newFilter.id); viewToFilter.SetFilterVisibility(newFilter.Id, true); }
That should be enough to get you motoring.
Sorry I am coming back to this, but my code just doesn't work.
I want to create a filter on a PlanView that filters all the structural columns below the current level. Here my code so far:
private static ParameterFilterElement CreateViewFilter(Document doc, BuiltInCategory category, Level CurrentLevel, Level LowerLevel) { ElementId paramId = new ElementId(BuiltInParameter.FAMILY_BASE_LEVEL_PARAM); List<ElementId> catIds = new List<ElementId>(); catIds.Add(new ElementId(category)); List<FilterRule> filterRules = new List<FilterRule>(); filterRules.Add(ParameterFilterRuleFactory.CreateEqualsRule(paramId, LowerLevel.Id)); ParameterFilterElement elemFilter = null; string filterName = CurrentLevel.Name + "_ExcludeColumnsBelow"; // Search for existing filters with same name List<FilterElement> filterList = new FilteredElementCollector(doc).WherePasses(new ElementClassFilter(typeof(FilterElement))).ToElements().Cast<FilterElement>().ToList(); foreach (ParameterFilterElement filter in filterList) { if (filter.Name == filterName) // Filter Exists, update rules and use existing filter { elemFilter = filter; elemFilter.ClearRules(); elemFilter.SetRules(filterRules); break; } } if (elemFilter == null) // Doesn't Exist, create new filter { elemFilter = ParameterFilterElement.Create(doc, filterName, catIds, filterRules); } return elemFilter; }
The error message I get, is: One of the given rules refers to a parameter that does not apply to this filter's categories.
The category is BuiltInCategory.OST_StructuralColumns;
I am lost. Would be great if someone has an idea.
regards
Christian
Maybe to illustrate a bit. This is what I would like to do.
Any ideas, whats wrong with the code?
regards
Christian
I got it:
ElementId paramId_base = new ElementId(BuiltInParameter.SCHEDULE_BASE_LEVEL_PARAM); ElementId paramId_top = new ElementId(BuiltInParameter.SCHEDULE_TOP_LEVEL_PARAM);
and its not BuiltInParameter.FAMILY_BASE_LEVEL_PARAM or BuiltInParameter.FAMILY_TOP_LEVEL_PARAM.
Holy cow.
Christian