2025-04-24 20:56:44 +08:00
|
|
|
|
using Autodesk.Revit.DB;
|
|
|
|
|
|
using Autodesk.Revit.UI.Selection;
|
|
|
|
|
|
|
2026-02-21 16:31:24 +08:00
|
|
|
|
namespace ShrlAlgoToolkit.RevitCore.Assists;
|
2025-04-24 20:56:10 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取当前模型或链接模型的实体元素
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|