这个例子用 API 重新对视图过滤器的功能的实现。
创建视图过滤规则的逻辑:
ParameterFilterRuleFactory
创建FilterRule
,例如:PFRF.CreateBeginsWithRule(paramId, RuleValue, CaseSensitive)
ElementParameterFilter
: ElementParameterFilter elemParamFilter = new ElementParameterFilter(filterRule);
ParameterFilterElement
:ParameterFilterElement.Create(m_doc, myFilter.Key, categoryIdSet, elemFilter);
创建过滤规则,数值比较与字符串操作:ParameterFilterRuleFactory
namespace Autodesk.Revit.DB
{
public class ParameterFilterRuleFactory : IDisposable
{
public static FilterRule CreateBeginsWithRule(ElementId parameter, string value, bool caseSensitive);
public static FilterRule CreateContainsRule(ElementId parameter, string value, bool caseSensitive);
public static FilterRule CreateEndsWithRule(ElementId parameter, string value, bool caseSensitive);
public static FilterRule CreateEqualsRule(ElementId parameter, ElementId value);
public static FilterRule CreateEqualsRule(ElementId parameter, int value);
public static FilterRule CreateEqualsRule(ElementId parameter, double value, double epsilon);
public static FilterRule CreateEqualsRule(ElementId parameter, string value, bool caseSensitive);
public static FilterRule CreateGreaterOrEqualRule(ElementId parameter, string value, bool caseSensitive);
public static FilterRule CreateGreaterOrEqualRule(ElementId parameter, double value, double epsilon);
public static FilterRule CreateGreaterOrEqualRule(ElementId parameter, int value);
public static FilterRule CreateGreaterOrEqualRule(ElementId parameter, ElementId value);
public static FilterRule CreateGreaterRule(ElementId parameter, double value, double epsilon);
public static FilterRule CreateGreaterRule(ElementId parameter, int value);
public static FilterRule CreateGreaterRule(ElementId parameter, ElementId value);
public static FilterRule CreateGreaterRule(ElementId parameter, string value, bool caseSensitive);
public static FilterRule CreateHasNoValueParameterRule(ElementId parameter);
public static FilterRule CreateHasValueParameterRule(ElementId parameter);
public static FilterRule CreateIsAssociatedWithGlobalParameterRule(ElementId parameter, ElementId value);
public static FilterRule CreateIsNotAssociatedWithGlobalParameterRule(ElementId parameter, ElementId value);
public static FilterRule CreateLessOrEqualRule(ElementId parameter, int value);
public static FilterRule CreateLessOrEqualRule(ElementId parameter, string value, bool caseSensitive);
public static FilterRule CreateLessOrEqualRule(ElementId parameter, ElementId value);
public static FilterRule CreateLessOrEqualRule(ElementId parameter, double value, double epsilon);
public static FilterRule CreateLessRule(ElementId parameter, int value);
public static FilterRule CreateLessRule(ElementId parameter, double value, double epsilon);
public static FilterRule CreateLessRule(ElementId parameter, ElementId value);
public static FilterRule CreateLessRule(ElementId parameter, string value, bool caseSensitive);
public static FilterRule CreateNotBeginsWithRule(ElementId parameter, string value, bool caseSensitive);
public static FilterRule CreateNotContainsRule(ElementId parameter, string value, bool caseSensitive);
public static FilterRule CreateNotEndsWithRule(ElementId parameter, string value, bool caseSensitive);
public static FilterRule CreateNotEqualsRule(ElementId parameter, string value, bool caseSensitive);
public static FilterRule CreateNotEqualsRule(ElementId parameter, double value, double epsilon);
public static FilterRule CreateNotEqualsRule(ElementId parameter, int value);
public static FilterRule CreateNotEqualsRule(ElementId parameter, ElementId value);
public static FilterRule CreateSharedParameterApplicableRule(string parameterName);
}
}
对多个过滤规则进行组合:ElementFilter elemFilter = FiltersUtil.CreateElementFilterFromFilterRules(rules);
IList<ElementFilter> elemFilters = new List<ElementFilter>();
foreach (FilterRule filterRule in filterRules){
ElementParameterFilter elemParamFilter = new ElementParameterFilter(filterRule);
elemFilters.Add(elemParamFilter);
}
LogicalAndFilter elemFilter = new LogicalAndFilter(elemFilters);
创建过滤器:
ElementFilter elemFilter = FiltersUtil.CreateElementFilterFromFilterRules(rules);
IList<ElementId> categoryIdList = myFilter.Value.GetCategoryIds();
ISet<ElementId> categoryIdSet = new HashSet<ElementId>(categoryIdList);
ParameterFilterElement.Create(m_doc, "过滤器名称1", categoryIdSet, elemFilter);