Running the command results in this output. But there are only 6 doors in the model (3 added by each user), so where do the other 7 come from?
Lets look at these 2 lines in more detail:
FilteredElementCollector collector = new FilteredElementCollector(documnent); IList<Element> elements = collector.OfCategory(BuiltInCategory.OST_Doors).ToList();
The FilteredElementCollector is the class that the Revit API uses to filter and collect elements in the model. The first line is a constructor that creates a new FilteredElementCollector.
The next line uses this collector to create a list of elements that belong to the built-in category OST_Doors. But this does more than get the 6 door instances that we want. It also collects the 7 door family types that are loaded in the model, hence the 13 elements that are in the list.
To restrict the filter to find only family instances, the FilteredElementCollector.OfClass method can be used and the that line re-written to:
IList<Element> elements = collector.OfCategory(BuiltInCategory.OST_Doors).OfClass(typeof(FamilyInstance)).ToList();
With this change, the list will have only the 6 family instances of doors, which is what we want for the next step.