Files
Shrlalgo.RvKits/ShrlAlgoToolkit.Revit/Assists/BuiltEnumDictionary.cs
2025-04-24 20:56:44 +08:00

72 lines
2.7 KiB
C#

using Autodesk.Revit.DB;
namespace ShrlAlgoToolkit.Revit.Assists
{
public static class BuiltEnumDictionary
{
#if REVIT2025
public static string ToLabel(this ForgeTypeId source)
{
if (ParameterUtils.IsBuiltInParameter(source)) return LabelUtils.GetLabelForBuiltInParameter(source);
if (ParameterUtils.IsBuiltInGroup(source)) return LabelUtils.GetLabelForGroup(source);
if (UnitUtils.IsUnit(source)) return LabelUtils.GetLabelForUnit(source);
if (UnitUtils.IsSymbol(source)) return LabelUtils.GetLabelForSymbol(source);
if (SpecUtils.IsSpec(source)) return LabelUtils.GetLabelForSpec(source);
return LabelUtils.GetLabelForDiscipline(source);
}
#endif
public static Dictionary<T, string> GetBuiltInDictionary<T>()
where T : Enum
{
var dict = new Dictionary<T, string>();
foreach (object enumItem in Enum.GetValues(typeof(T)))
{
string name = string.Empty;
switch (enumItem)
{
#if REVIT2020
case BuiltInCategory category:
name = LabelUtils.GetLabelFor(category);
break;
#endif
case BuiltInParameter param:
name = LabelUtils.GetLabelFor(param);
break;
#if REVIT2018 || REVIT2020
case ParameterType type:
name = LabelUtils.GetLabelFor(type);
break;
case BuiltInParameterGroup group:
name = LabelUtils.GetLabelFor(group);
break;
case UnitType unitType:
name = LabelUtils.GetLabelFor(unitType);
break;
case DisplayUnitType displayUnitType:
name = LabelUtils.GetLabelFor(displayUnitType);
break;
case UnitSymbolType symbolType:
name = LabelUtils.GetLabelFor(symbolType);
break;
#endif
case ElementType elementType:
name = elementType.Name;
break;
case Element element:
name = element.Name;
break;
}
#if REVIT2025
if (enumItem is ForgeTypeId forgeTypeId)
{
var label = LabelUtils.GetLabelForBuiltInParameter(forgeTypeId);
}
#endif
dict.Add((T)enumItem, name);
}
return dict;
}
}
}