Files
ShrlAlgoToolkit/ShrlAlgoToolkit.Revit/Assists/DwgBlockSelection.cs

54 lines
1.6 KiB
C#
Raw Normal View History

2025-04-24 20:56:44 +08:00
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
namespace ShrlAlgoToolkit.Revit.Assists;
2025-04-24 20:56:10 +08:00
/// <summary>
/// dwg块选择过滤
/// </summary>
public class DwgBlockSelection : ISelectionFilter
{
private Element e;
public bool AllowElement(Element elem)
{
e = elem;
return e.Document.GetElement(e.GetTypeId()) is CADLinkType;
}
public bool AllowReference(Reference reference, XYZ position)
{
//块
var instance = e.GetGeometryObjectFromReference(reference) as GeometryInstance;
if (instance == null)
{
return false;
}
////dwg
//foreach (var dwgIns in e.get_Geometry(new Options()))
//{
// if (dwgIns is not GeometryInstance item) continue;
// //遍历dwg包含的所有内容
// foreach (var obj in item.SymbolGeometry)
// {
// return obj is GeometryInstance ins && !ins.SymbolGeometry.Any();
// }
//}
//if (selectBlock == null)
//{
// return false;
//}
//块是否包含子块
//foreach (var item in instance.SymbolGeometry)
//{
// if (item is GeometryInstance)
// {
// return false;
// }
//}
//var isNest = selectBlock.SymbolGeometry.OfType<GeometryInstance>().Any();
return /*!isNest &&*/ reference.ElementReferenceType == ElementReferenceType.REFERENCE_TYPE_INSTANCE
&& instance.GraphicsStyleId != ElementId.InvalidElementId;
}
}