From 8ed89c4c1335503c47307ace26c9fd993bc6ee43 Mon Sep 17 00:00:00 2001 From: Alan Rynne Date: Mon, 18 Sep 2023 14:43:30 +0200 Subject: [PATCH] fix(rvt): Exclude Schedules from Everything filter, only send when category is selected (#2928) Schedules caused slowness in the sending process, and are usually redundant when sending the entire model. --- .../UI/ConnectorBindingsRevit.Selection.cs | 60 ++++++++----------- 1 file changed, 25 insertions(+), 35 deletions(-) diff --git a/ConnectorRevit/ConnectorRevit/UI/ConnectorBindingsRevit.Selection.cs b/ConnectorRevit/ConnectorRevit/UI/ConnectorBindingsRevit.Selection.cs index 6d8cd32413..a6ee20f194 100644 --- a/ConnectorRevit/ConnectorRevit/UI/ConnectorBindingsRevit.Selection.cs +++ b/ConnectorRevit/ConnectorRevit/UI/ConnectorBindingsRevit.Selection.cs @@ -228,10 +228,7 @@ private List GetSelectionFilterObjects(ISpeckleConverter converter, ISe { var linkedDocs = GetLinkedDocuments(); - var allDocs = new List - { - CurrentDoc.Document - }; + var allDocs = new List { CurrentDoc.Document }; allDocs.AddRange(linkedDocs.Values); var selection = new List(); @@ -330,13 +327,17 @@ private static List GetEverything(Dictionary linke selection.AddRange(currentDoc.Views2D()); selection.AddRange(currentDoc.Views3D()); - selection.AddRange(currentDoc.GetSupportedElements(revitDocumentAggregateCache)); + // We specifically exclude `TableView` elements (Schedules) until schedule extraction has been improved for performance. + var elements = currentDoc.GetSupportedElements(revitDocumentAggregateCache).Where(e => e is not TableView); + selection.AddRange(elements); selection.AddRange(currentDoc.GetSupportedTypes(revitDocumentAggregateCache)); //and these for every linked doc foreach (var linkedDoc in linkedDocs.Values) { - selection.AddRange(linkedDoc.GetSupportedElements(revitDocumentAggregateCache)); // includes levels + // We specifically exclude `TableView` elements (Schedules) until schedule extraction has been improved for performance. + var linkedElements = linkedDoc.GetSupportedElements(revitDocumentAggregateCache).Where(e => e is not TableView); + selection.AddRange(linkedElements); // includes levels selection.AddRange(linkedDoc.GetSupportedTypes(revitDocumentAggregateCache)); } @@ -351,26 +352,20 @@ private List GetSelectionByCategory(ISelectionFilter filter, List() - .TryGet(cat); - if (revitCategory == null) continue; + var revitCategory = revitDocumentAggregateCache.GetOrInitializeWithDefaultFactory().TryGet(cat); + if (revitCategory == null) + continue; catIds.Add(revitCategory.Id); } using var categoryFilter = new ElementMulticategoryFilter(catIds); - foreach (var doc in allDocs) { using var collector = new FilteredElementCollector(doc); selection.AddRange( - collector - .WhereElementIsNotElementType() - .WhereElementIsViewIndependent() - .WherePasses(categoryFilter) - .ToList() + collector.WhereElementIsNotElementType().WhereElementIsViewIndependent().WherePasses(categoryFilter).ToList() ); } return selection; @@ -433,13 +428,12 @@ private static List GetSelectionByView(List views, Dictionary !selection.Any(s => s.UniqueId == x.UniqueId)) //exclude elements already added from other views - .ToList() - ); - + docCollector + .WhereElementIsNotElementType() + .WhereElementIsViewIndependent() + .Where(x => !selection.Any(s => s.UniqueId == x.UniqueId)) //exclude elements already added from other views + .ToList() + ); foreach (var linkedDoc in linkedDocs) { @@ -452,13 +446,13 @@ private static List GetSelectionByView(List views, Dictionary x.IsPhysicalElement()) - .Where(x => !selection.Any(s => s.UniqueId == x.UniqueId)) //exclude elements already added from other views - .ToList() - ); + linkedDocCollector + .WhereElementIsNotElementType() + .WhereElementIsViewIndependent() + //.Where(x => x.IsPhysicalElement()) + .Where(x => !selection.Any(s => s.UniqueId == x.UniqueId)) //exclude elements already added from other views + .ToList() + ); #else //check if linked doc is visible in main doc @@ -471,7 +465,6 @@ private static List GetSelectionByView(List views, Dictionary !selection.Any(s => s.UniqueId == x.UniqueId))); #endif - } } return selection; @@ -534,10 +527,7 @@ private static List GetSelectionByProjectInfo(ISelectionFilter filter) return selection; } - private static List GetSelectionByWorkset( - ISelectionFilter filter, - List allDocs - ) + private static List GetSelectionByWorkset(ISelectionFilter filter, List allDocs) { var selection = new List(); var worksetFilter = filter as ListSelectionFilter;