From 5420d74970c90455cbf5860336deae1b2da1b1ca Mon Sep 17 00:00:00 2001 From: SergeyNefyodov Date: Fri, 20 Sep 2024 21:55:20 +0200 Subject: [PATCH] add Document.ResolveDefaultElementTypeId support --- .../Descriptors/DocumentDescriptor.cs | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/source/RevitLookup/Core/ComponentModel/Descriptors/DocumentDescriptor.cs b/source/RevitLookup/Core/ComponentModel/Descriptors/DocumentDescriptor.cs index 7b167684..f19c1234 100644 --- a/source/RevitLookup/Core/ComponentModel/Descriptors/DocumentDescriptor.cs +++ b/source/RevitLookup/Core/ComponentModel/Descriptors/DocumentDescriptor.cs @@ -45,6 +45,7 @@ public Func Resolve(Document context, string target, ParameterInfo[] { nameof(Document.Close) when parameters.Length == 0 => Variants.Disabled, nameof(Document.PlanTopologies) when parameters.Length == 0 => ResolvePlanTopologies, + nameof(Document.GetDefaultElementTypeId) => ResolveDefaultElementTypeId, #if REVIT2024_OR_GREATER nameof(Document.GetUnusedElements) => ResolveGetUnusedElements, nameof(Document.GetAllUnusedElements) => ResolveGetAllUnusedElements, @@ -63,6 +64,26 @@ IVariants ResolvePlanTopologies() return Variants.Single(topologies); } + IVariants ResolveDefaultElementTypeId() + { + var values = Enum.GetValues(typeof(ElementTypeGroup)); + var variants = new Variants(values.Length); + + foreach (ElementTypeGroup value in values) + { + var result = _document.GetDefaultElementTypeId(value); + if (result is not null && result != ElementId.InvalidElementId) + { + variants.Add(result, $"{value.ToString()}: {result.ToElement(_document)!.Name}"); + } + else + { + variants.Add(result, $"{value.ToString()}: {result}"); + } + } + + return variants; + } #if REVIT2024_OR_GREATER IVariants ResolveGetUnusedElements() @@ -76,7 +97,6 @@ IVariants ResolveGetAllUnusedElements() } #endif } - public void RegisterExtensions(IExtensionManager manager) { manager.Register(nameof(GlobalParametersManager.GetAllGlobalParameters), GlobalParametersManager.GetAllGlobalParameters);