Resolving duplicate tags Step 2 – finding only family instances

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.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s