Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dimitrie/cnx 635 curtain wall doors duplicated geometry #309

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ public async Task HighlightModel(string modelCardId)
.SendFilter.NotNull()
.GetObjectIds()
.Select(uid => ElementIdHelper.GetElementIdFromUniqueId(activeUIDoc.Document, uid))
.Where(el => el is not null)
.Cast<ElementId>()
.ToList();
}

Expand All @@ -113,6 +115,8 @@ public async Task HighlightModel(string modelCardId)
elementIds = receiverModelCard
.BakedObjectIds.NotNull()
.Select(uid => ElementIdHelper.GetElementIdFromUniqueId(activeUIDoc.Document, uid))
.Where(el => el is not null)
.Cast<ElementId>()
.ToList();
}

Expand All @@ -138,7 +142,11 @@ public async Task HighlightObjects(IReadOnlyList<string> objectIds)
?? throw new SpeckleException("Unable to retrieve active UI document");

await HighlightObjectsOnView(
objectIds.Select(uid => ElementIdHelper.GetElementIdFromUniqueId(activeUIDoc.Document, uid)).ToList()
objectIds
.Select(uid => ElementIdHelper.GetElementIdFromUniqueId(activeUIDoc.Document, uid))
.Where(el => el is not null)
.Cast<ElementId>()
.ToList()
)
.ConfigureAwait(false);
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ public async Task Send(string modelCardId)
List<ElementId> revitObjects = modelCard
.SendFilter.NotNull()
.GetObjectIds()
.Select(uid => activeUIDoc.Document.GetElement(uid).Id)
.Select(uid => activeUIDoc.Document.GetElement(uid))
.Where(el => el is not null) // NOTE: elements can get deleted from the host app.
.Select(el => el.Id)
.ToList();

if (revitObjects.Count == 0)
Expand Down Expand Up @@ -249,6 +251,9 @@ private async Task RunExpirationChecks()
}

// Note: We're using unique ids as application ids in revit, so cache eviction must happen by those.
// NOTE: this is currently broken when deleting freestanding elements (e.g. unhosted elements)
// To reproduce, draw two unconnected walls, send, delete one wall -> no expiration notice
// I do not yet know the solution besides going back to element ids, but it would mean revisiting why we switched to unique ids (conflicting ids)
var objUniqueIds = objectIdsList
.Select(id => new ElementId(Convert.ToInt32(id)))
.Select(doc.GetElement)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
using Autodesk.Revit.DB;
using Speckle.Sdk;

namespace Speckle.Connectors.RevitShared;

public static class ElementIdHelper
{
public static ElementId GetElementIdFromUniqueId(Document doc, string uniqueId)
public static ElementId? GetElementIdFromUniqueId(Document doc, string uniqueId)
{
Element element = doc.GetElement(uniqueId);
if (element == null)
{
throw new SpeckleException($"Cannot find element with UniqueId: {uniqueId}");
}

return element.Id;
return element?.Id;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,15 @@ private List<Element> UnpackElements(IEnumerable<Element> elements)
private List<Element> PackCurtainWallElements(List<Element> elements)
{
var ids = elements.Select(el => el.Id).ToArray();
var doc = _revitContext.UIApplication?.ActiveUIDocument.Document!;
elements.RemoveAll(element =>
(element is Mullion m && ids.Contains(m.Host.Id)) || (element is Panel p && ids.Contains(p.Host.Id))
(element is Mullion m && ids.Contains(m.Host.Id))
|| (element is Panel p && ids.Contains(p.Host.Id))
|| (
element is FamilyInstance { Host: not null } f
&& doc.GetElement(f.Host.Id) is Wall { CurtainGrid: not null }
&& ids.Contains(f.Host.Id)
)
);
return elements;
}
Expand Down
Loading