30 lines
876 B
C#
30 lines
876 B
C#
|
|
using Autodesk.Revit.DB;
|
|||
|
|
|
|||
|
|
namespace ShrlAlgoToolkit.Revit.Assists;
|
|||
|
|
|
|||
|
|
public static class CategoryAssist
|
|||
|
|
{
|
|||
|
|
public static Element ToElement(this ElementId elementId, Document doc)
|
|||
|
|
{
|
|||
|
|
return doc.GetElement(elementId);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public static Category ToCategory(this BuiltInCategory builtInCategory, Document doc)
|
|||
|
|
{
|
|||
|
|
return Category.GetCategory(doc, builtInCategory);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public static BuiltInCategory ToBuiltInCategory(this Category category)
|
|||
|
|
{
|
|||
|
|
#if REVIT2018 || REVIT2020
|
|||
|
|
var builtInCategory = (BuiltInCategory)category.Id.IntegerValue;
|
|||
|
|
#elif REVIT2025
|
|||
|
|
var builtInCategory = (BuiltInCategory)category.Id.Value;
|
|||
|
|
#endif
|
|||
|
|
|
|||
|
|
return Enum.IsDefined(typeof(BuiltInCategory), builtInCategory)
|
|||
|
|
? builtInCategory
|
|||
|
|
: throw new ArgumentNullException(nameof(category), "不存在该内建类别");
|
|||
|
|
}
|
|||
|
|
}
|