/* ============================================================================== * 功能描述:管网检查 * 创 建 者:Garrett * 创建日期:2019/6/11 16:09:09 * ==============================================================================*/ using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using Autodesk.Revit.DB; using SAGA.DotNetUtils.Extend; using SAGA.RevitUtils.Extends; using SAGA.RevitUtils.MEP; using ServiceRevitLib.Extend; using ServiceRevitLib.Mode; namespace ServiceRevitLib.DataCheck.Mode { /// /// SagaCheck /// class PipeCheck : CheckBase { public override void Check() { try { base.Check(); #region var document = m_Doc; var elements = document.FilterElements().ToList(); foreach (var element in elements) { if (element.IsStart()) { //标记立管,所有连接点都未记录则删除 //if (!connectors.Any(c => c.IsConnected)) //{ // item.ErrorCode = "001"; // reportItem.ResultItems.Add(item); //} continue; } var item = new PipeCheckResult(); item.SystemName = element.GetSystemTypeName(); item.Id = element.Id.ToString(); var code = GetErrorCode(element, item.SystemName); if (IsNeedExport(code)) { item.Result = ResultState.Failure; item.ResultMsg = GetErrorDescription(code); Content.Add(item); } } #endregion } catch (Exception e) { Result = ResultState.Failure; ResultMsg = $"{e.Message}\r\n{e.StackTrace}"; } } /// /// 获取错误码 /// /// /// /// private PipeCheckErrorCode GetErrorCode(Element element,string systemName) { PipeCheckErrorCode errorCode = PipeCheckErrorCode.Code_000; Domain[] domains = new Domain[] { Domain.DomainPiping, Domain.DomainHvac }; do { foreach (Domain domain in domains) { var connectors = element.GetConnectors(domain); if (connectors.Any(c => !c.IsConnected)) { errorCode = PipeCheckErrorCode.Code_001; } } if (errorCode == PipeCheckErrorCode.Code_001 && element.GetLocationCurve() is Line line) { //一端不连接的立管不导出 if (line.Direction.IsParallel(XYZ.BasisZ)) { errorCode = PipeCheckErrorCode.Code_003; } } var endElements = element.GetFirstElements(null, e => e is MEPCurve || e.IsEquipment()); List curves = endElements.OfType().ToList(); foreach (var mepCurve in curves) { if (systemName != mepCurve.GetSystemTypeName()) { errorCode = PipeCheckErrorCode.Code_002; break; } } } while (false); return errorCode; } /// /// 获取错误描述 /// /// /// private string GetErrorDescription(PipeCheckErrorCode errorCode) { string description = errorCode.GetDescription()+",请检查"; return description; } /// /// 是否需要导出 /// /// /// private bool IsNeedExport(PipeCheckErrorCode errorCode) { return errorCode == PipeCheckErrorCode.Code_001 || errorCode == PipeCheckErrorCode.Code_002; } enum PipeCheckErrorCode { [Description("管段连接正确")] Code_000, [Description("末端未连接任何设备")] Code_001, [Description("管道两端连接了不同类型的管道")] Code_002, Code_003, [Description("误报")] Code_004 } } }