Files
Shrlalgo.RvKits/ShrlAlgoToolkit.RevitCore/Assists/DwgElementSelection.cs
2026-02-21 16:31:24 +08:00

38 lines
1.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
namespace ShrlAlgoToolkit.RevitCore.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;
}
}