/* ============================================================================== * 功能描述:ElementExtension * 创 建 者:Garrett * 创建日期:2019/6/25 11:51:43 * ==============================================================================*/ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using Autodesk.Revit.DB; using Autodesk.Revit.DB.Mechanical; using RevitToJBim.Common; using RevitToJBim.MBI; using SAGA.RevitUtils.Extends; namespace RevitToJBim.Extension { /// /// ElementExtension /// public static class ElementExtension { public static string GetFamilyName(this Element element) { return element.GetFamily()?.Name; } /// /// 获取设备的种族类型编码 ATFC /// 族名称的命名规则:ATFC-风机盘管 /// /// public static string GetFamilyCode(this Element element) { string code = ""; if (element is FamilyInstance fi) { string familyName = fi.GetFamilyName(); if (familyName == null) return code; //族名称的命名规则:ATFC-风机盘管 int index = familyName.IndexOf('-'); if (index != -1 && index + 1 != familyName.Length) code = familyName.Substring(0, familyName.IndexOf('-')); //移除前面和后面的空格 code = code.Trim(); } return code; } /// /// 判断是否为设备 设备族为4位 /// ATVR - 多联机 - 室内机 - 双向气流 - 天花板嵌入式 /// /// /// public static bool IsEquipment(this Element element) { bool result = false; if (element is FamilyInstance fi) { var family = fi.GetFamilyName(); result = Regex.IsMatch(family, $"{MBIRegexPattern.IsEquip}"); } return result; } /// /// 判断是否为设备部件 设备族为6位 /// /// /// public static bool IsEquipmentPart(this Element element) { bool result = false; if (element is FamilyInstance fi) { var family = fi.GetFamilyName(); result = Regex.IsMatch(family, $"{MBIRegexPattern.IsEquipPart}"); } return result; } /// /// 判断是否为信标 /// /// /// public static bool IsBeacon(this Element elem) { var family = elem.GetFamilyName(); return family != null && (Regex.IsMatch(family, MBIRegexPattern.IsBeacon)); } /// /// 判断是否为空间,判断周长是否为零 /// 如果周长为零,是删除的空间 /// /// /// 是否检查周长为零 /// public static bool IsSpace(this Element elem, bool ischeckzero = true) { var isspace = false; if (elem is Space space) { //空间比较特殊,周长为零就相当于删除 isspace = !ischeckzero || !(space.IsDeleteSpace()); //限制所用空间的阶段 if (isspace) { //增加过滤效率,如果上一步正确菜继续往下执行。 isspace = space.IsPhase1Space(); } if (isspace) { isspace = space.IsViewLevel(); } } return isspace; } } }