Message 1 of 5
Find all categories with instances

Not applicable
07-21-2017
04:08 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello, everyone! I'm creating the add-in, some kind of custom filter, and firstly it fills ComboBox with all Categories in the project (code is attached below).
But, in fact, some categories are empty and haven't any instances in the project, and they're useless in Combobox.
public void CreateCategoryList() { FilteredElementCollector elements = new FilteredElementCollector (doc)
.WhereElementIsElementType();
categories = elements .Where(x => x.Category != null) .Select(x => x.Category) .Distinct(new CategoryComparer()) .ToList(); categories.Sort(new CategoryNameComparer()); foreach (Category c in categories) { ComboBoxItem cbi = new ComboBoxItem(); cbi.HorizontalContentAlignment = HorizontalAlignment.Left; cbi.Padding = new Thickness(30, 0, 0, 0); cbi.Content = c.Name; cbi.Tag = c; comboBox.Items.Add(cbi); } }
Can anyone help me to find only those categories which have instances in the project? Thanks!