/* ==============================================================================
* 功能描述:SagaCheck
* 创 建 者:Garrett
* 创建日期:2019/6/11 16:09:09
* ==============================================================================*/
using System;
using System.Linq;
using Autodesk.Revit.DB;
using SAGA.RevitUtils.Extends;
using ServiceRevitLib.Extend;
using ServiceRevitLib.Mode;
using ServiceRevitLib.Utils;
namespace ServiceRevitLib.DataCheck.Mode
{
///
/// SagaCheck
///
class FamilyNameCheck : CheckBase
{
public FamilyNameCheck()
{
ReferenceSheet = "参考-revit分类";
}
public override void Check()
{
try
{
base.Check();
#region
var ccategories = DataCheckRule.GetCodeCheckCategories();
var categories = m_Doc.Settings.Categories;
foreach (DCR_CodeCheckCategory ccategory in ccategories)
{
try
{
var category = categories.get_Item(ccategory.Name);
if (category == null) continue;
BuiltInCategory builtInCategory = (BuiltInCategory)category.Id.IntegerValue;
var elements = m_Doc.GetElements(builtInCategory);
var groupByFamily = elements.GroupBy(t => t.GetFamilyName());
foreach (IGrouping grouping in groupByFamily)
{
var subElements = grouping.ToList();
var subElement = subElements.FirstOrDefault();
if (subElement is FamilyInstance fi)
{
var result = new FamilyNameCheckResult();
result.FamilyName = grouping.Key;
if (fi.IsEquipment() || fi.IsEquipmentPart() || fi.IsBeacon())
{
result.Result = ResultState.Success;
}
else
{
result.Result = ResultState.Failure;
result.ResultMsg = "请检查族名称编码是否符合要求";
}
Content.Add(result);
}
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
#endregion
}
catch (Exception e)
{
Result = ResultState.Failure;
ResultMsg = $"{e.Message}\r\n{e.StackTrace}";
}
}
}
}