From a6a42e5507d1ea3d125c2578e27bfd12d8d5bf7c Mon Sep 17 00:00:00 2001 From: Jonathon Broughton <760691+jsdbroughton@users.noreply.github.com> Date: Fri, 2 Aug 2024 16:08:08 +0100 Subject: [PATCH 1/2] fix(Navisworks) - Improve SelectionSet extraction with error handling and documentation (#3608) Improve SelectionSet extraction with error handling and documentation - Refactor `ExtractSelectionSets` method for better reusability - Add comprehensive XML documentation for clarity - Implement null checks to prevent potential exceptions - Optimize LINQ query for `SelectionSet` extraction from GUIDs --- .../Other/SelectionBuilder.cs | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/ConnectorNavisworks/ConnectorNavisworks/Other/SelectionBuilder.cs b/ConnectorNavisworks/ConnectorNavisworks/Other/SelectionBuilder.cs index 80fcc3b514..9cae7b675a 100644 --- a/ConnectorNavisworks/ConnectorNavisworks/Other/SelectionBuilder.cs +++ b/ConnectorNavisworks/ConnectorNavisworks/Other/SelectionBuilder.cs @@ -288,7 +288,12 @@ private HashSet GetObjectsFromSavedSets() // Saved Sets filter stores Guids of the selection sets. This can be converted to ModelItem pseudoIds var selections = _filter.Selection.Select(guid => new Guid(guid)).ToList(); - var savedItems = selections.Select(Application.ActiveDocument.SelectionSets.ResolveGuid).OfType(); + + // Resolve the saved items and extract the inner selection sets when folder items are encountered + var savedItems = selections + .Select(guid => Application.ActiveDocument.SelectionSets.ResolveGuid(guid)) + .SelectMany(ExtractSelectionSets) + .ToList(); foreach (var item in savedItems) { @@ -308,6 +313,45 @@ private HashSet GetObjectsFromSavedSets() return _uniqueModelItems; } + /// + /// Recursively extracts SelectionSet objects from the given item. + /// + /// The object to extract SelectionSets from. Can be a SelectionSet, FolderItem, or any other object. + /// An IEnumerable of SelectionSet objects extracted from the item and its children (if applicable). + /// Thrown if the input item is null. + static IEnumerable ExtractSelectionSets(object selection) + { + if (selection == null) + { + throw new ArgumentNullException(nameof(selection), "Input item cannot be null."); + } + + switch (selection) + { + case SelectionSet selectionSet: + yield return selectionSet; + break; + case FolderItem folderItem: + if (folderItem.Children == null) + { + yield break; + } + foreach (var childItem in folderItem.Children) + { + if (childItem == null) + { + continue; + } + + foreach (var extractedSet in ExtractSelectionSets(childItem)) + { + yield return extractedSet; + } + } + break; + } + } + /// /// Populates the hierarchy by adding ancestor and descendant items to the unique model items. /// The unique model items have already been processed to validate that they are not hidden. From 0ec1f105f7ad1d2c9c884b1c55de8015fdcd7baa Mon Sep 17 00:00:00 2001 From: Ralph Wessel <150629054+r-wessel@users.noreply.github.com> Date: Fri, 2 Aug 2024 16:10:22 +0100 Subject: [PATCH 2/2] Restored helper function for faster library/object creation (#3610) --- .../AddOn/Sources/AddOn/Commands/CreateCommand.cpp | 3 +++ ConnectorArchicad/AddOn/Sources/AddOn/Commands/CreateDoor.cpp | 1 + .../AddOn/Sources/AddOn/Commands/CreateGridElement.cpp | 1 + .../AddOn/Sources/AddOn/Commands/CreateObject.cpp | 3 +++ .../AddOn/Sources/AddOn/Commands/CreateSkylight.cpp | 1 + .../AddOn/Sources/AddOn/Commands/CreateWindow.cpp | 1 + 6 files changed, 10 insertions(+) diff --git a/ConnectorArchicad/AddOn/Sources/AddOn/Commands/CreateCommand.cpp b/ConnectorArchicad/AddOn/Sources/AddOn/Commands/CreateCommand.cpp index 95f74c0232..b159461dd1 100644 --- a/ConnectorArchicad/AddOn/Sources/AddOn/Commands/CreateCommand.cpp +++ b/ConnectorArchicad/AddOn/Sources/AddOn/Commands/CreateCommand.cpp @@ -4,6 +4,7 @@ #include "CreateCommand.hpp" #include "LibpartImportManager.hpp" #include "ClassificationImportManager.hpp" +#include "APIHelper.hpp" #include "FieldNames.hpp" #include "OnExit.hpp" #include "ExchangeManager.hpp" @@ -123,6 +124,8 @@ GS::ObjectState CreateCommand::Execute (const GS::ObjectState& parameters, GS::P parameters.Get (GetFieldName (), objectStates); ACAPI_CallUndoableCommand (GetUndoableCommandName (), [&] () -> GSErrCode { + LibraryHelper helper (false); + GS::Array applicationObjects; AttributeManager* attributeManager = AttributeManager::GetInstance (); diff --git a/ConnectorArchicad/AddOn/Sources/AddOn/Commands/CreateDoor.cpp b/ConnectorArchicad/AddOn/Sources/AddOn/Commands/CreateDoor.cpp index baa597270d..381589b14a 100644 --- a/ConnectorArchicad/AddOn/Sources/AddOn/Commands/CreateDoor.cpp +++ b/ConnectorArchicad/AddOn/Sources/AddOn/Commands/CreateDoor.cpp @@ -6,6 +6,7 @@ #include "RealNumber.h" #include "DGModule.hpp" #include "LibpartImportManager.hpp" +#include "APIHelper.hpp" #include "FieldNames.hpp" #include "OnExit.hpp" #include "ExchangeManager.hpp" diff --git a/ConnectorArchicad/AddOn/Sources/AddOn/Commands/CreateGridElement.cpp b/ConnectorArchicad/AddOn/Sources/AddOn/Commands/CreateGridElement.cpp index d18939ce1c..2b17b910a8 100644 --- a/ConnectorArchicad/AddOn/Sources/AddOn/Commands/CreateGridElement.cpp +++ b/ConnectorArchicad/AddOn/Sources/AddOn/Commands/CreateGridElement.cpp @@ -1,6 +1,7 @@ #include "CreateGridElement.hpp" #include "ResourceIds.hpp" #include "ObjectState.hpp" +#include "APIHelper.hpp" #include "Utility.hpp" #include "Objects/Level.hpp" #include "Objects/Point.hpp" diff --git a/ConnectorArchicad/AddOn/Sources/AddOn/Commands/CreateObject.cpp b/ConnectorArchicad/AddOn/Sources/AddOn/Commands/CreateObject.cpp index d94909765d..7381415197 100644 --- a/ConnectorArchicad/AddOn/Sources/AddOn/Commands/CreateObject.cpp +++ b/ConnectorArchicad/AddOn/Sources/AddOn/Commands/CreateObject.cpp @@ -1,6 +1,7 @@ #include "CreateObject.hpp" #include "APIMigrationHelper.hpp" +#include "APIHelper.hpp" #include "LibpartImportManager.hpp" #include "ResourceIds.hpp" #include "Utility.hpp" @@ -130,6 +131,8 @@ GS::ObjectState CreateObject::Execute (const GS::ObjectState& parameters, GS::Pr parameters.Get (FieldNames::MeshModels, meshModels); ACAPI_CallUndoableCommand (GetUndoableCommandName (), [&] () -> GSErrCode { + LibraryHelper helper (false); + AttributeManager* attributeManager = AttributeManager::GetInstance (); LibpartImportManager* libpartImportManager = LibpartImportManager::GetInstance (); for (ModelInfo meshModel : meshModels) { diff --git a/ConnectorArchicad/AddOn/Sources/AddOn/Commands/CreateSkylight.cpp b/ConnectorArchicad/AddOn/Sources/AddOn/Commands/CreateSkylight.cpp index fd56fb1efb..dab3d245cb 100644 --- a/ConnectorArchicad/AddOn/Sources/AddOn/Commands/CreateSkylight.cpp +++ b/ConnectorArchicad/AddOn/Sources/AddOn/Commands/CreateSkylight.cpp @@ -7,6 +7,7 @@ #include "RealNumber.h" #include "DGModule.hpp" #include "LibpartImportManager.hpp" +#include "APIHelper.hpp" #include "FieldNames.hpp" #include "OnExit.hpp" #include "ExchangeManager.hpp" diff --git a/ConnectorArchicad/AddOn/Sources/AddOn/Commands/CreateWindow.cpp b/ConnectorArchicad/AddOn/Sources/AddOn/Commands/CreateWindow.cpp index 1cf6a03e98..aac1284db6 100644 --- a/ConnectorArchicad/AddOn/Sources/AddOn/Commands/CreateWindow.cpp +++ b/ConnectorArchicad/AddOn/Sources/AddOn/Commands/CreateWindow.cpp @@ -7,6 +7,7 @@ #include "RealNumber.h" #include "DGModule.hpp" #include "LibpartImportManager.hpp" +#include "APIHelper.hpp" #include "FieldNames.hpp" #include "OnExit.hpp" #include "ExchangeManager.hpp"