Files
Shrlalgo.RvKits/ShrlAlgoToolkit.Revit/Assists/DwgElementSelection.cs

38 lines
1.6 KiB
C#
Raw Normal View History

2025-07-11 09:20:23 +08:00
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
namespace ShrlAlgoToolkit.Revit.Assists;
/// <summary>
/// <c>
/// dwg元素选择过滤ObjectType.PointOnElement默认选择块选择曲线使用 ElementReferenceType.REFERENCE_TYPE_LINEAR
/// var dwgElemSelection = new DwgElementSelection(ElementReferenceType.REFERENCE_TYPE_LINEAR);
/// var refer = UiDocument.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.PointOnElement, dwgElemSelection);
/// Element elem = Document.GetElement(refer);
/// GeometryElement geoElem = elem.get_Geometry(new Options());
/// GeometryObject geoObj = elem.GetGeometryObjectFromReference(refer);
/// 图层:(Document.GetElement(geoObj.GraphicsStyleId) as GraphicsStyle).GraphicsStyleCategory.Name
/// 元素类型geoObj?.GetType().Name
/// </c>
/// </summary>
public class DwgElementSelection : ISelectionFilter
{
private readonly ElementReferenceType elementReferenceType;
private Element e;
public GeometryObject SelectedElement { get; private set; }
public DwgElementSelection(ElementReferenceType elementReferenceType = ElementReferenceType.REFERENCE_TYPE_INSTANCE)
{ this.elementReferenceType = elementReferenceType; }
public bool AllowElement(Element elem)
{
e = elem;
return e.Document.GetElement(e.GetTypeId()) is CADLinkType;
}
public bool AllowReference(Reference reference, XYZ position)
{
return reference.ElementReferenceType == elementReferenceType &&
e.GetGeometryObjectFromReference(reference).GraphicsStyleId != ElementId.InvalidElementId;
}
}