When I use DesignAutomation (Autodesk Forge) to count the number of BuiltInCategory.OST_SpecialityEquiosystem
elements visible on the Revit file by getting the FilteredElementCollector lstEleCollector = new FilteredElementCollector (doc, doc.ActiveView.Id);
.But I realized that there is no Active View concept in Design Automation. So is there a way to count all the elements that appear in the rvt file?
Asked
Active
Viewed 343 times
1

Rahul Bhobe
- 4,165
- 4
- 17
- 32

TAN Phan Viet VTID9
- 43
- 5
1 Answers
1
To count all elements of a given category in a document you should use FilteredElementCollector.OfCategory():
FilteredElementCollector collector = new FilteredElementCollector(doc);
ICollection<Element> collection = collector.OfCategory(BuiltInCategory.OST_SpecialityEquiosystem)
.ToElements();
int count = collection.Count;
This will however give you all elements in the document. To find elements in a given view, you will need to know the view id. If you do not know the view id, you can iterate through all views in a document and find the view you are looking for.
FilteredElementCollector collector = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Views);
foreach (Autodesk.Revit.DB.View v in collector.ToElements())
{
if (v && v.Name == "My Special View")
viewId = v.Id;
}
Then you can call the API you already know with this viewId
instead of doc.ActiveView.Id
.
FilteredElementCollector lstEleCollector = new FilteredElementCollector (doc, viewId);
ICollection<Element> collection = lstEleCollector.OfCategory(BuiltInCategory.OST_SpecialityEquiosystem)
.ToElements();
int count = collection.Count;
Also refer our very basic forge-countdeletewalls-revit code sample which does something similar to what you are attempting. It counts walls, doors, floors and windows in a given document.

Rahul Bhobe
- 4,165
- 4
- 17
- 32