From 98e2b474960b8f73643b8f67a0f5410ab59f7199 Mon Sep 17 00:00:00 2001 From: Dimitrie Stefanescu Date: Fri, 9 Aug 2024 19:19:47 +0200 Subject: [PATCH] fixes cnx-217: nested families not sent unless they are in a group (#128) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: now sends nested families (wip) * fix: explodes nested families into subcomponents correctly * fix: removed unecessary using --------- Co-authored-by: Oğuzhan Koral <45078678+oguzhankoral@users.noreply.github.com> --- .../HostApp/SendSelectionUnpacker.cs | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/Connectors/Revit/Speckle.Connectors.RevitShared/HostApp/SendSelectionUnpacker.cs b/Connectors/Revit/Speckle.Connectors.RevitShared/HostApp/SendSelectionUnpacker.cs index 1f494497a..440da5a2b 100644 --- a/Connectors/Revit/Speckle.Connectors.RevitShared/HostApp/SendSelectionUnpacker.cs +++ b/Connectors/Revit/Speckle.Connectors.RevitShared/HostApp/SendSelectionUnpacker.cs @@ -13,6 +13,10 @@ namespace Speckle.Connectors.Revit.HostApp; /// explodes them into sub constituent objects, recursively. /// /// +/// Nested families: +/// explodes them into sub constituent objects, recursively. +/// +/// /// Curtain walls: /// If parent wall is part of selection, does not select individual elements out. Otherwise, selects individual elements (Panels, Mullions) as atomic objects. /// @@ -31,7 +35,7 @@ public IEnumerable UnpackSelection(IEnumerable selectionElemen { // Note: steps kept separate on purpose. // Step 1: unpack groups - var atomicObjects = UnpackGroups(selectionElements); + var atomicObjects = UnpackElements(selectionElements); // Step 2: pack curtain wall elements, once we know the full extent of our flattened item list. // The behaviour we're looking for: @@ -40,16 +44,32 @@ public IEnumerable UnpackSelection(IEnumerable selectionElemen } // This needs some yield refactoring - private List UnpackGroups(IEnumerable elements) + private List UnpackElements(IEnumerable elements) { - var unpackedElements = new List(); + var unpackedElements = new List(); // note: could be a hashset/map so we prevent duplicates (?) foreach (var element in elements) { if (element is Group g) { + // POC: this might screw up generating hosting rel generation here, because nested families in groups get flattened out by GetMemberIds(). + // in other words, if a group contains nested families, .GetMemberIds() will return all "exploded" families. var groupElements = g.GetMemberIds().Select(_contextStack.Current.Document.GetElement); - unpackedElements.AddRange(UnpackGroups(groupElements)); + unpackedElements.AddRange(UnpackElements(groupElements)); + } + else if (element is FamilyInstance familyInstance) + { + var familyElements = familyInstance + .GetSubComponentIds() + .Select(_contextStack.Current.Document.GetElement) + .ToArray(); + + if (familyElements.Length != 0) + { + unpackedElements.AddRange(UnpackElements(familyElements)); + } + + unpackedElements.Add(familyInstance); } else {