I have a simple Revit plugin to count multiple elements by category and display the totals in a task dialog. The code works fine with one category. When I add more that 1 line to count multiple categories anything after the 1st line returns a result of 0 as in the image below. I can run any of the 3 categories below alone and correct results are returned. Any ideas why multiple lines will not display results? Thanks for any help!
using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.Attributes;
namespace MyRevitCommands
{
[TransactionAttribute(TransactionMode.ReadOnly)]
public class SomeData : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
//Get UIDocument
UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
//Create Filtered Element Collector
FilteredElementCollector collector = new FilteredElementCollector(doc);
//Create Filter
ElementCategoryFilter lineFilter = new ElementCategoryFilter(BuiltInCategory.OST_Lines);
ElementCategoryFilter tagFilter = new ElementCategoryFilter(BuiltInCategory.OST_Tags);
ElementCategoryFilter wallFilter = new ElementCategoryFilter(BuiltInCategory.OST_Walls);
//Apply Filter
IList<Element> lines = collector.WherePasses(lineFilter).WhereElementIsNotElementType().ToElements();
int lineCount = lines.Count;
IList<Element> tags = collector.WherePasses(tagFilter).WhereElementIsNotElementType().ToElements();
int tagCount = tags.Count;
IList<Element> walls = collector.WherePasses(wallFilter).WhereElementIsNotElementType().ToElements();
int wallCount = walls.Count;
**TaskDialog.Show("Model Data", string.Format(
"Lines: " + lineCount
+ Environment.NewLine + "Tags: " + tagCount
+ Environment.NewLine + "Walls: " + wallCount
));**
return Result.Succeeded;
}
}
}