/*------------------------------------------------------------------------- * 功能描述:SelectionFilter * 作者:xulisong * 创建时间: 2019/5/23 14:14:35 * 版本号:v1.0 * -------------------------------------------------------------------------*/ using Autodesk.Revit.DB; using Autodesk.Revit.UI.Selection; using FWindSoft.Revit.Extension; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace FWindSoft.Revit.Common { public class SelectionFilter : ISelectionFilter { private Predicate m_AllowElement; private Func m_AllowReference; public SelectionFilter(Predicate allowElement, Func allowReference) { m_AllowElement = allowElement; m_AllowReference = allowReference; } public bool AllowElement(Element elem) { if (m_AllowElement != null) { return m_AllowElement.Invoke(elem); } return true; } public bool AllowReference(Reference reference, XYZ position) { if (m_AllowReference != null) { return m_AllowReference.Invoke(reference,position); } return true; } } /// /// 类型选择过滤器 /// public class TypeSelectionFilter : ISelectionFilter { private Type m_Type; public TypeSelectionFilter(Type type) { m_Type = type; } public bool AllowElement(Element elem) { return elem.GetType() == m_Type; } public bool AllowReference(Reference reference, XYZ position) { return true; } } /// /// 类别过滤器 /// public class CategorySelectionFilter : ISelectionFilter { private BuiltInCategory m_BuiltInCategory; public CategorySelectionFilter(BuiltInCategory builtInCategory) { m_BuiltInCategory= builtInCategory; } public bool AllowElement(Element elem) { var bit = elem.GetCategory(); return bit== m_BuiltInCategory; } public bool AllowReference(Reference reference, XYZ position) { return true; } } /// /// 多类别过滤器 /// public class CategoriesSelectionFilter : ISelectionFilter { private readonly List m_Categories = new List(); public CategoriesSelectionFilter(BuiltInCategory bic) { m_Categories.Add(bic); } public CategoriesSelectionFilter(List categories) { m_Categories.AddRange(categories??new List()); } public bool AllowElement(Element elem) { if (!m_Categories.Any()) { return false; } var useCategory = elem.GetCategory(); return m_Categories.Any(p => p == useCategory); } public bool AllowReference(Reference reference, XYZ position) { return true; } } }