using Autodesk.Revit.DB; using Autodesk.Revit.UI.Selection; namespace ShrlAlgoToolkit.Revit.Assists; /// /// /// 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 /// /// 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; } }