Skip to content

Commit

Permalink
fix(rvt): Exclude Schedules from Everything filter, only send when ca…
Browse files Browse the repository at this point in the history
…tegory is selected (#2928)

Schedules caused slowness in the sending process, and are usually redundant when sending the entire model.
  • Loading branch information
AlanRynne authored Sep 18, 2023
1 parent a97066d commit 8ed89c4
Showing 1 changed file with 25 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,7 @@ private List<Element> GetSelectionFilterObjects(ISpeckleConverter converter, ISe
{
var linkedDocs = GetLinkedDocuments();

var allDocs = new List<Document>
{
CurrentDoc.Document
};
var allDocs = new List<Document> { CurrentDoc.Document };
allDocs.AddRange(linkedDocs.Values);

var selection = new List<Element>();
Expand Down Expand Up @@ -330,13 +327,17 @@ private static List<Element> GetEverything(Dictionary<ElementId, Document> 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));
}

Expand All @@ -351,26 +352,20 @@ private List<Element> GetSelectionByCategory(ISelectionFilter filter, List<Docum

foreach (var cat in catFilter.Selection)
{
var revitCategory = revitDocumentAggregateCache
.GetOrInitializeWithDefaultFactory<Category>()
.TryGet(cat);
if (revitCategory == null) continue;
var revitCategory = revitDocumentAggregateCache.GetOrInitializeWithDefaultFactory<Category>().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;
Expand Down Expand Up @@ -433,13 +428,12 @@ private static List<Element> GetSelectionByView(List<View> views, Dictionary<Ele

using var docCollector = new FilteredElementCollector(CurrentDoc.Document, view.Id);
selection.AddRange(
docCollector
.WhereElementIsNotElementType()
.WhereElementIsViewIndependent()
.Where(x => !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)
{
Expand All @@ -452,13 +446,13 @@ private static List<Element> GetSelectionByView(List<View> views, Dictionary<Ele
#if !REVIT2020 && !REVIT2021 && !REVIT2022 && !REVIT2023
using var linkedDocCollector = new FilteredElementCollector(CurrentDoc.Document, view.Id, linkedDoc.Key);
selection.AddRange(
linkedDocCollector
.WhereElementIsNotElementType()
.WhereElementIsViewIndependent()
//.Where(x => 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
Expand All @@ -471,7 +465,6 @@ private static List<Element> GetSelectionByView(List<View> views, Dictionary<Ele
.AddRange(linkedDoc.Value.GetSupportedElements(revitDocumentAggregateCache)
.Where(x => !selection.Any(s => s.UniqueId == x.UniqueId)));
#endif

}
}
return selection;
Expand Down Expand Up @@ -534,10 +527,7 @@ private static List<Element> GetSelectionByProjectInfo(ISelectionFilter filter)
return selection;
}

private static List<Element> GetSelectionByWorkset(
ISelectionFilter filter,
List<Document> allDocs
)
private static List<Element> GetSelectionByWorkset(ISelectionFilter filter, List<Document> allDocs)
{
var selection = new List<Element>();
var worksetFilter = filter as ListSelectionFilter;
Expand Down

0 comments on commit 8ed89c4

Please sign in to comment.