123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- /* ==============================================================================
- * 功能描述:VerticalPipeUtil
- * 创 建 者:Garrett
- * 创建日期:2019/11/5 15:35:20
- * ==============================================================================*/
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Autodesk.Revit.DB;
- using FWindSoft.Revit;
- using FWindSoft.Wpf;
- using NPOI.SS.UserModel;
- using Saga.PlugIn.ModelCheck;
- using SAGA.DotNetUtils;
- using SAGA.DotNetUtils.Extend;
- using SAGA.DotNetUtils.Others;
- using SAGA.RevitUtils.MEP;
- namespace Saga.PlugIn.VerticalPipeCheck
- {
- /// <summary>
- /// VerticalPipeUtil
- /// </summary>
- class VerticalPipeUtil
- {
- /// <summary>
- /// 执行立管检查
- /// </summary>
- /// <param name="upPath"></param>
- /// <param name="downPath"></param>
- /// <param name="savePath"></param>
- /// <returns></returns>
- public static Tuple<int,int> Execute(string upPath,string downPath,string savePath)
- {
- try
- {
- var upPipes = GetVerticalMEPCurves(upPath,true);
- var downPipes = GetVerticalMEPCurves(downPath, false);
- Action<List<VerticalPipe>, List<VerticalPipe>, string, bool> check = (pipes1, pipes2, path, isup) =>
- {
- string fileName = path.GetFileName();
- foreach (VerticalPipe pipe in pipes1)
- {
- var pipes = pipes2.Where(t => t.OpenXyz.IsAlmostEqualTo(pipe.OpenXyz));
- if (pipes.Any())
- {
- pipe.TargetFileName = fileName;
- pipe.TargetPath = path;
- pipe.IsRight = true;
- string tip = isup ? "下" : "上";
- pipe.RMessage = $"在{tip}层相应位置到了对应的立管。Id:{pipes.FirstOrDefault().MepCurve.Id}";
- }
- else
- {
- pipe.TargetFileName = fileName;
- pipe.TargetPath = path;
- pipe.IsRight = false;
- string tip = isup ? "下" : "上";
- pipe.RMessage = $"在{tip}层相应位置找不到对应的立管,请检查模型";
- }
- }
- };
- check(upPipes, downPipes, downPath, true);
- check(downPipes, upPipes, upPath, false);
- List<VerticalPipe> results=new List<VerticalPipe>(upPipes);
- results.AddRange(downPipes);
- results.Sort(new CommonComparer<VerticalPipe>((x, y) => {return x.IsRight.CompareTo(y.IsRight); }));
- #region Save
- //重置workbook准备保存结果
- DCRExport.ClearWorkbook(DCRExport.VerticalPipePath);
- //保存
- ExportResult(results);
- DCRExport.Save(savePath, DCRExport.GetWorkbook());
- return new Tuple<int, int>(upPipes.Count,downPipes.Count);
- #endregion
- }
- catch (Exception e)
- {
- MessageShowBase.Show(e);
- }
- return null;
- }
- /// <summary>
- /// 获取所有的立管
- /// </summary>
- /// <param name="path"></param>
- /// <param n
- /// ame="isup"></param>
- /// <returns></returns>
- public static List<VerticalPipe> GetVerticalMEPCurves(string path,bool isup)
- {
- var doc=RevitCore.App.OpenDocumentFile(path);
- string fileName = path.GetFileName();
- var mepcurves = doc.GetElements<MEPCurve>();
- List<VerticalPipe> verticalPipes=new List<VerticalPipe>();
- foreach (MEPCurve mepCurve in mepcurves)
- {
- bool result = false;
- var curve = mepCurve.GetLocationCurve();
- if (curve is Line line)
- {
- if (line.Direction.IsParallel(XYZ.BasisZ))
- {
- var start = line.StartPoint();
- var end = line.EndPoint();
- XYZ point = null;
- if (isup)
- {
- point = start.Z.IsThan(end.Z) ? end : start;
- }
- else
- {
- point = start.Z.IsThan(end.Z) ? start : end;
- }
- Connector connector = mepCurve.GetNearConnector(point);
- if (connector!=null&&!connector.IsConnected)
- {
- VerticalPipe verticalPipe=new VerticalPipe();
- verticalPipe.MepCurve = mepCurve;
- verticalPipe.OpenXyz = point;
- verticalPipe.Path = path;
- verticalPipe.FileName = fileName;
- verticalPipes.Add(verticalPipe);
- }
- }
- }
- }
- return verticalPipes;
- }
- /// <summary>
- /// 检查结果汇总
- /// </summary>
- /// <param name="list"></param>
- /// <param name="context"></param>
- private static void ExportResult(List<VerticalPipe> list)
- {
- try
- {
- IWorkbook book = DCRExport.GetWorkbook();
- string sheetName = "立管对齐检查";
- ISheet sheet = book.GetSheet(sheetName);
- #region 添加数据
- int index = 3;
- //添加 共检查XXX条数据,未通过检查的如下 提示
- IRow rowTip = sheet.CreateRow(index - 1);
- //rowTip.AddCell(0, $"总检查{list.Count}条数据,未通过检查的如下", DataCheckNPOIStyle.Title);
- foreach (var result in list)
- {
- index++;
- IRow rowN = sheet.CreateRow(index);
- DataCheckNPOIStyle style = result.IsRight ? DataCheckNPOIStyle.Content : DataCheckNPOIStyle.Error;
- int j = -1;
- rowN.AddCell(++j, result.FileName, style);
- rowN.AddCell(++j, result.Path, style);
- rowN.AddCell(++j, result.MepCurve.Id.ToString(), style);
- rowN.AddCell(++j, result.MepCurve.GetSystemTypeName(), style);
- rowN.AddCell(++j, result.TargetFileName, style);
- rowN.AddCell(++j, result.TargetPath, style);
- string rowN4 = result.IsRight ? "通过" : "不通过";
- rowN.AddCell(++j, rowN4, style);
- rowN.AddCell(++j, result.RMessage, style);
- }
- #endregion
- }
- catch (Exception e)
- {
- MessageShowBase.Show(e);
- }
- }
- }
- class VerticalPipe
- {
- public MEPCurve MepCurve { get; set; }
- public XYZ OpenXyz { get; set; }
- public string Path { get; set; }
- public string FileName { get; set; }
- public string TargetPath { get; set; }
- public string TargetFileName { get; set; }
- /// <summary>
- /// 是否通过较验
- /// </summary>
- public bool IsRight { get; set; }
- /// <summary>
- /// 提示信息
- /// </summary>
- public string RMessage { get; set; }
- }
- }
|