123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- /* ==============================================================================
- * 功能描述:Revit族参数完整性检查
- * 创 建 者:Garrett
- * 创建日期:2018/10/23 15:08:55
- * ==============================================================================*/
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Autodesk.Revit.DB;
- using NPOI.SS.UserModel;
- using SAGA.DotNetUtils.Others;
- using SAGA.RevitUtils.Extends;
- namespace Saga.PlugIn.ModelCheck
- {
- /// <summary>
- /// UnitCheck
- /// </summary>
- [ParseIndex(Index = 12)]
- class ParameterIntegrityCheck : ModeCheckBase
- {
- public ParameterIntegrityCheck()
- {
- Name = "Revit族参数完整性检查";
- }
-
- public override bool Check()
- {
- if (!RBase.IsRight)
- {
- IsRight = RBase.IsRight;
- return IsRight;
- }
- IsRight = FamilyNameCodeCheck();
- return IsRight;
- }
- /// <summary>
- /// 族名称编码规范检查
- /// </summary>
- /// <returns></returns>
- private bool FamilyNameCodeCheck()
- {
- bool unitResult = true;
- foreach (SagaSignCheckResult signResult in RBase.Results)
- {
- var doc = signResult.RDocument;
- var instances = doc.GetFamilyInstances();
- var mbiItems = instances.Where(t => t.IsEquipment() || t.IsEquipmentPart()).ToList();
- var familyGroups = mbiItems.GroupBy(t => t.GetFamilyName());
- foreach (IGrouping<string, Element> familyGroup in familyGroups)
- {
- string familyName = familyGroup.Key;
- Element fi = familyGroup.FirstOrDefault();
- var result = GetCheckResult(fi);
- if (result == null) continue;
- result.FamilyName = familyName;
- result.RBase = signResult;
- Results.Add(result);
- }
- }
- return Results.All(t => t.IsRight);
- }
- /// <summary>
- /// 获取检测结果
- /// </summary>
- /// <param name="fi"></param>
- /// <returns></returns>
- private ParameterIntegrityCheckResult GetCheckResult(Element fi)
- {
- var result = new ParameterIntegrityCheckResult(){IsRight = true};
- string localName = ModelCheckConst.EquipLocalName;
- string localId = ModelCheckConst.EquipLocalID;
- var localNameParameter = fi.GetParameter(localName);
- var localIdParameter = fi.GetParameter(localId);
- List<string> list=new List<string>();
- if(localIdParameter==null)
- list.Add(localId);
- if(localNameParameter==null)
- list.Add(localName);
- if (list.Count > 0)
- {
- result.IsRight = false;
- result.RMessage = $"缺失的参数为:{string.Join("、", list)}";
- }
- return result;
- }
- //[DataCheckProcessAspect]
- public override void Export()
- {
- // Check();
- try
- {
- IWorkbook book = DCRExport.GetWorkbook();
- ISheet sheet = book.GetSheet(Name);
- #region 添加数据
- int index = 3;
- foreach (ParameterIntegrityCheckResult result in Results)
- {
- SagaSignCheckResult rbase = result.RBase as SagaSignCheckResult;
- if (rbase == null)
- continue;
- //数量多过,只显示有问题的
- if (result.IsRight) continue;
-
- index++;
- IRow rowN = sheet.CreateRow(index);
- DataCheckNPOIStyle style = result.IsRight ? DataCheckNPOIStyle.Content : DataCheckNPOIStyle.Error;
- int j = -1;
- rowN.AddCell(++j, result.FamilyName, style);
- string rowN4 = result.IsRight ? "通过" : "不通过";
- rowN.AddCell(++j, rowN4, style);
- rowN.AddCell(++j, result.RMessage, style);
- }
- #endregion
- }
- catch (Exception e)
- {
- MessageShowBase.Show(e);
- }
- }
- }
- class ParameterIntegrityCheckResult : ModeCheckResultBase
- {
- public string FamilyName { get; set; }
- public string Id { get; set; }
- }
- }
|