Reputation: 83
I am creating a plugin for Revit 2019 and want to select all the instances of specific family and type through API. "ElementClassFilter" is available in Revit sdk to filter the elements but I want to display all instances of same type in blue lines. I have filtered the specific type through "ElementClassFilter" but looking for how to select them in revit through API.
The following code is for filtering elements of specific family and type.
ElementClassFilter filter = new ElementClassFilter(typeof(FamilyInstance));
FilteredElementCollector collector = new FilteredElementCollector(document);
collector.WherePasses(filter);
var query = from element in collector where element.Name == "Single-Standard" select element;
List<FamilyInstance> familyInstances = query.Cast<FamilyInstance>().ToList<FamilyInstance>();
But I want to show all instances of same family and type in the following image
"Window: Single-Standard" image
Upvotes: 0
Views: 2997
Reputation: 573
UIApplication UIapp = commandData.Application;
UIDocument UIdoc = UIapp.ActiveUIDocument;
Document doc = UIdoc.Document;
FilteredElementCollector elementCollector = new FilteredElementCollector(doc);
elementCollector.OfClass(typeof(FamilyInstance));
Selection sel = UIdoc.Selection;
sel.SetElementIds(elementCollector.ToList().Select(o => o.Id).ToList()); //User selection
This is a simple example to how to set the user selection. For mor info of revit Selection class you can visit this link.
Upvotes: 1