From c2bafc66133a67bac6388454bd4ff52c451c5359 Mon Sep 17 00:00:00 2001 From: Dimitrie Stefanescu Date: Tue, 3 Dec 2024 17:02:10 +0000 Subject: [PATCH] Dim/type change cach invalidation (#391) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: handles changing an element type in revit via the edit type dialog looks for any types in the modified object list and adds all objects that have that type as modified * feat: minor cleanup * feat: naming, comments * fix: minor linq changes --------- Co-authored-by: Oğuzhan Koral <45078678+oguzhankoral@users.noreply.github.com> --- .../Bindings/RevitSendBinding.cs | 44 ++++++++++--------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/RevitSendBinding.cs b/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/RevitSendBinding.cs index 818542eea..c491b7fac 100644 --- a/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/RevitSendBinding.cs +++ b/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/RevitSendBinding.cs @@ -351,15 +351,32 @@ private async Task RunExpirationChecks() } var objUniqueIds = new List(); + var changedIds = ChangedObjectIds.Keys.ToList(); + + // Handling type changes: if an element's type is changed, we need to mark as changed all objects that have that type. + // Step 1: get any changed types + var elementTypeIdsList = changedIds + .Select(e => doc.GetElement(e)) + .OfType() + .Select(el => el.Id) + .ToArray(); + + // Step 2: Find all elements of the changed types, and add them to the changed ids list. + if (elementTypeIdsList.Length != 0) + { + using var collector = new FilteredElementCollector(doc); + var collectorElements = collector + .WhereElementIsNotElementType() + .Where(e => elementTypeIdsList.Contains(e.GetTypeId())); + foreach (var elm in collectorElements) + { + changedIds.Add(elm.Id); + } + } foreach (var sender in senders) { - // if (sender.SendFilter is null) // NOTE: RunExpirationChecks sometimes triggered unnecessarily before send and, we didn't set up yet IdMap, if so we do not need to deal with it - // { - // continue; - // } - - foreach (var changedElementId in ChangedObjectIds.Keys) + foreach (var changedElementId in changedIds) { if (sender.SendFilter?.IdMap?.TryGetValue(changedElementId.ToString(), out var id) ?? false) { @@ -368,21 +385,6 @@ private async Task RunExpirationChecks() } } - // foreach (var changedElementId in ChangedObjectIds.Keys.ToArray()) - // { - // foreach (var sender in senders) - // { - // if (sender.SendFilter.NotNull().IdMap is null) - // { - // continue; - // } - // if (sender.SendFilter.NotNull().IdMap.NotNull().ContainsKey(changedElementId.ToString())) - // { - // objUniqueIds.Add(sender.SendFilter.NotNull().IdMap.NotNull()[changedElementId.ToString()]); - // } - // } - // } - var unpackedObjectIds = _elementUnpacker.GetUnpackedElementIds(objUniqueIds); _sendConversionCache.EvictObjects(unpackedObjectIds);