Skip to content

Commit

Permalink
fixes cnx-217: nested families not sent unless they are in a group (#128
Browse files Browse the repository at this point in the history
)

* fix: now sends nested families (wip)

* fix: explodes nested families into subcomponents correctly

* fix: removed unecessary using

---------

Co-authored-by: Oğuzhan Koral <[email protected]>
  • Loading branch information
didimitrie and oguzhankoral authored Aug 9, 2024
1 parent e85c568 commit 98e2b47
Showing 1 changed file with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ namespace Speckle.Connectors.Revit.HostApp;
/// <description>explodes them into sub constituent objects, recursively.</description>
/// </item>
/// <item>
/// <term>Nested families: </term>
/// <description>explodes them into sub constituent objects, recursively.</description>
/// </item>
/// <item>
/// <term>Curtain walls: </term>
/// <description>If parent wall is part of selection, does not select individual elements out. Otherwise, selects individual elements (Panels, Mullions) as atomic objects.</description>
/// </item>
Expand All @@ -31,7 +35,7 @@ public IEnumerable<Element> UnpackSelection(IEnumerable<Element> 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:
Expand All @@ -40,16 +44,32 @@ public IEnumerable<Element> UnpackSelection(IEnumerable<Element> selectionElemen
}

// This needs some yield refactoring
private List<Element> UnpackGroups(IEnumerable<Element> elements)
private List<Element> UnpackElements(IEnumerable<Element> elements)
{
var unpackedElements = new List<Element>();
var unpackedElements = new List<Element>(); // 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
{
Expand Down

0 comments on commit 98e2b47

Please sign in to comment.