2025-02-10 20:53:40 +08:00
|
|
|
|
using Autodesk.Revit.DB;
|
2024-09-22 11:05:41 +08:00
|
|
|
|
|
2025-02-10 20:53:40 +08:00
|
|
|
|
namespace ShrlAlgo.Toolkit.Revit.Helpers;
|
2024-09-22 11:05:41 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 创建参数的参数过滤器
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class ViewFilterAssist
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 类别视图过滤器
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="builtInCategory"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public static ElementParameterFilter CreateCategoryFilter(BuiltInCategory builtInCategory)
|
|
|
|
|
|
{
|
|
|
|
|
|
ElementParameterFilter commonElementParameterFilter = null;
|
|
|
|
|
|
List<FilterRule> commonFilterRules = new();
|
|
|
|
|
|
List<ElementId> commonCategoryForRules = new() { new(builtInCategory) };
|
|
|
|
|
|
if (FilterCategoryRule.AllCategoriesFilterable(commonCategoryForRules))
|
|
|
|
|
|
{
|
|
|
|
|
|
FilterCategoryRule commonCategoryRule = new(commonCategoryForRules);
|
|
|
|
|
|
commonFilterRules.Add(commonCategoryRule);
|
|
|
|
|
|
commonElementParameterFilter = new ElementParameterFilter(commonFilterRules);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return commonElementParameterFilter;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 参数的参数过滤器
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="builtInCategory"></param>
|
|
|
|
|
|
/// <param name="rules"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public static ElementParameterFilter CreateParameterFilter(BuiltInCategory builtInCategory, params FilterRule[] rules)
|
|
|
|
|
|
{
|
|
|
|
|
|
ElementParameterFilter commonFilter = null;
|
|
|
|
|
|
List<FilterRule> commonFilterRules = new();
|
|
|
|
|
|
List<ElementId> commonCategoryForRules = new() { new(builtInCategory) };
|
|
|
|
|
|
//判断类别是否可用于过滤器
|
|
|
|
|
|
if (FilterCategoryRule.AllCategoriesFilterable(commonCategoryForRules))
|
|
|
|
|
|
{
|
|
|
|
|
|
//类别规则
|
|
|
|
|
|
FilterCategoryRule commonCategoryRule = new(commonCategoryForRules);
|
|
|
|
|
|
commonFilterRules.Add(commonCategoryRule);
|
|
|
|
|
|
foreach (var rule in rules)
|
|
|
|
|
|
{
|
|
|
|
|
|
commonFilterRules.Add(rule);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
commonFilter = new ElementParameterFilter(commonFilterRules);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return commonFilter;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 视图过滤器过滤规则
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="parameter"></param>
|
|
|
|
|
|
/// <param name="value">元素Id或整型值</param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public static FilterRule CreateParameterFilterRule(BuiltInParameter parameter, int value)
|
|
|
|
|
|
{
|
|
|
|
|
|
var paramId = new ElementId(parameter);
|
|
|
|
|
|
var filterRule = ParameterFilterRuleFactory.CreateEqualsRule(paramId, value);
|
|
|
|
|
|
return filterRule;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|