- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
I've been stuck on this for a few hours now and I just can't work out how to add a rule to a view filter that exists. I'm calling GetElementFilter() on line 10 below, which can return two options: an ElementParameterFilter or an ElementLogicalFilter. I'm not too sure of the logic behind it but I'm getting an ElementLogicalFilter.
I'm then calling the GetFilters() [line 15] on my ElementLogicalFilter and adding a new filter to the list but I then need to pass that to SetElementFilter() [line 23] but that only takes one ElementFilter. What I am missing here and how complicated can this get???
Thanks for reading. I've already checked the 2024 documentation and done my research but I couldn't find any help for that.
var allFilters = new FilteredElementCollector(doc)
.OfClass(typeof(ParameterFilterElement))
.WhereElementIsNotElementType()
.ToElements();
foreach (ParameterFilterElement filter in allFilters)
{
if (filter.Name == "MyFilterName")
{
var existElemFilter = filter.GetElementFilter();
if (existElemFilter is ElementLogicalFilter)
{
var existLogicalFilter = existElemFilter as ElementLogicalFilter;
IList<ElementFilter> existElemFilters = existLogicalFilter.GetFilters();
IList<ElementFilter> newPhaseFilter = new List<ElementFilter>()
{
new ElementParameterFilter(ParameterFilterRuleFactory.CreateEqualsRule(phaseCreatedPar.Id, viewPhasePar.AsElementId())) as ElementFilter
};
existElemFilters.Add(new LogicalAndFilter(newPhaseFilter));
filter.SetElementFilter(existElemFilters); // this needs an ElementFilter, not a list of them
}
}
}
Solved! Go to Solution.