Message 1 of 16
SetElementIds two times slower than Revit's window selection
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm trying to select all elements in the view to avoid having to drag window (PickBox) each time. However, whatever I do commandData.Application.ActiveUIDocument.Selection.SetElementIds method is always about two times slower, which can make a difference on larger projects.
Has SetElementIds been made purposefully slower or have I done something wrong?
The simplest example:
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace scripts
{
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class SelectAllElementsInViewAndInGroups : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
Document doc = commandData.Application.ActiveUIDocument.Document;
UIDocument uiDoc = commandData.Application.ActiveUIDocument;
var elementIdsInView = new FilteredElementCollector(doc, doc.ActiveView.Id)
.ToElementIds();
// Set the selection to these filtered elements
uiDoc.Selection.SetElementIds(elementIdsInView);
return Result.Succeeded;
}
}
}
Version to exclude elements inside groups (based on the comments below):
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System.Collections.Generic;
using System.Linq;
namespace scripts
{
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class SelectAllElementsInView : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
Document doc = commandData.Application.ActiveUIDocument.Document;
UIDocument uiDoc = commandData.Application.ActiveUIDocument;
View currentView = doc.ActiveView;
List<ElementId> ElementsNotInGroups = new FilteredElementCollector(doc, doc.ActiveView.Id)
.WhereElementIsNotElementType()
.Where(e => e.GroupId == ElementId.InvalidElementId)
.Select(e => e.Id)
.ToList();
uiDoc.Selection.SetElementIds(ElementsNotInGroups);
return Result.Succeeded;
}
}
}