using Autodesk.Revit.DB; using Autodesk.Revit.UI.Selection; namespace ShrlAlgoToolkit.Revit.Assists; /// /// 获取当前模型或链接模型的实体元素 /// public class ElementInLinkOrCurrentDocument : ISelectionFilter { public ElementInLinkOrCurrentDocument(Document doc) { this.doc = doc; } private readonly Document doc; public bool LastCheckedWasFromLink => null != LinkedDocument; public Document LinkedDocument { get; private set; } public bool AllowElement(Element e) { return true; } public bool AllowReference(Reference r, XYZ p) { LinkedDocument = null; var e = doc.GetElement(r); if (e is RevitLinkInstance li) { LinkedDocument = li.GetLinkDocument(); e = LinkedDocument.GetElement(r.LinkedElementId); } return e != null && e.CanHaveTypeAssigned() && e.HasPhases() && e.get_BoundingBox(null) != null && e.Category is { Parent: null } && e is not Panel; } }