123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- /* ==============================================================================
- * 功能描述: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
- {
- /// <summary>
- /// ElementExtension
- /// </summary>
- public static class ElementExtension
- {
- public static string GetFamilyName(this Element element)
- {
- return element.GetFamily()?.Name;
- }
- /// <summary>
- /// 获取设备的种族类型编码 ATFC
- /// 族名称的命名规则:ATFC-风机盘管
- /// </summary>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 判断是否为设备 设备族为4位
- /// ATVR - 多联机 - 室内机 - 双向气流 - 天花板嵌入式
- /// </summary>
- /// <param name="fi"></param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 判断是否为设备部件 设备族为6位
- /// </summary>
- /// <param name="fi"></param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 判断是否为信标
- /// </summary>
- /// <param name="elem"></param>
- /// <returns></returns>
- public static bool IsBeacon(this Element elem)
- {
- var family = elem.GetFamilyName();
- return family != null && (Regex.IsMatch(family, MBIRegexPattern.IsBeacon));
- }
- /// <summary>
- /// 判断是否为空间,判断周长是否为零
- /// 如果周长为零,是删除的空间
- /// </summary>
- /// <param name="elem"></param>
- /// <param name="ischeckzero">是否检查周长为零</param>
- /// <returns></returns>
- 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;
- }
- }
- }
|