/* ============================================================================== * 功能描述:SagaCheck * 创 建 者:Garrett * 创建日期:2019/6/11 16:09:09 * ==============================================================================*/ using System; using System.Collections.Generic; using System.Linq; using Autodesk.Revit.DB; using SAGA.DotNetUtils.Logger; using SAGA.RevitUtils.MEP; using ServiceRevitLib.Extend; using ServiceRevitLib.Mode; using ServiceRevitLib.Utils; namespace ServiceRevitLib.DataCheck.Mode { /// /// SagaCheck /// class SystemReferEquipCheck : CheckBase { public SystemReferEquipCheck() { ReferenceSheet = "参考-管网及相关设备"; } public override void Check() { try { base.Check(); #region m_EquipReferSystems = DataCheckRule.GetEquipReferSystems(); var elements = m_Doc.GetEqEcElements(); foreach (Element element in elements) { var result = GetCheckResult(element); if (result == null) continue; Content.Add(result); } #endregion } catch (Exception e) { Result = ResultState.Failure; ResultMsg = $"{e.Message}\r\n{e.StackTrace}"; } } private List m_EquipReferSystems; /// /// 获取检测结果 /// /// /// private SystemReferEquipCheckResult GetCheckResult(Element element) { var result = new SystemReferEquipCheckResult(); var code = element.GetFamilyCode(); // 可以与设备连接的系统 var referSystems = m_EquipReferSystems.FirstOrDefault(t => t.EquipName == code)?.Systems ?? new List(); if (referSystems.Count == 0) return null; result.FamilyName = element.GetFamilyName(); result.Id = element.Id.ToString(); var tuple = CheckConType(element, referSystems); if (tuple.Item2.Any()) { result.ResultMsg = $"连接件所连接的管道系统与规范不一致,请检查"; result.UnPassSystems += string.Join("、", tuple.Item2.ToArray()); result.Result = ResultState.Failure; } else { result.Result = ResultState.Success; } result.PassSystems += string.Join("、", tuple.Item1.ToArray()); return result; } /// /// 检查连接件连接的管道系统是否符合规范 /// /// 符合要求的系统名称 /// 不符合要求的系统名称 private Tuple, List> CheckConType(Element element, List referSystems) { List passList = new List(); List unpassList = new List(); var connectors = element.GetAllConnectors(); foreach (Connector connector in connectors) { try { var mepSystem = connector.MEPSystem; if (mepSystem == null) continue; var elementId = mepSystem.GetTypeId(); var type = element.Document.GetElement(elementId); if (!referSystems.Contains(type.Name)) { unpassList.Add(type.Name); } else { passList.Add(type.Name); } } catch (Exception e) { Log4Net.Info($"读取连接件系统错误。Id:{element.Id},Path:{element.Document.PathName}"); } } return new Tuple, List>(passList, unpassList); } } }