
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello all. I'm trying to figure something out, that I feel should be pretty simple, yet I cannot seem to grasp it.
I am trying to select all walls of a specific type.... more to the point, I'm trying to see if any walls of a specific type exist in the project so I can know whether or not I need to skip it (this is for a custom exporter I'm wroking on)
Here's what I have so far.
IList<BuiltInCategory> categories = new List<BuiltInCategory>(); categories.Add(BuiltInCategory.OST_Walls); //Built In categories gives us the Category ID for all revit categories. (walls, doors, etc) //Build a list of all Families under the given category IList<ElementType> families = new List<ElementType>(); //And a list of all instances of each family IList<Element> instances = new List<Element>(); //Filter for the current category ElementCategoryFilter categoryFilter; //filter for Elements within the category ElementCategoryFilter elementFilter; FilteredElementCollector collector = new FilteredElementCollector(document); //string debug = ""; foreach (BuiltInCategory category in categories) { categoryFilter = new ElementCategoryFilter(category); //Set the current category filter to the current category being exported //Gather a list of all Families in the given Type families = collector.WherePasses(categoryFilter).WhereElementIsElementType().Cast<ElementType>().ToList(); //debug = "Element Types:"; //foreach (ElementType f in families){ debug += "\n" + f.Name + " | " + f.Id;} MessageBox.Show(debug); foreach (ElementType el in families) { elementFilter = new ElementCategoryFilter(el.Id); instances = collector.WherePasses(elementFilter).Cast<Element>().ToList() ; if (instances.Count == 0) { continue; } //If there are no instances of it, i don't need to export it //debug = "Element Instances: "+ el.Name + el.Id; //foreach (Element f in instances) { debug += "\n" + f.Id; } MessageBox.Show(debug); } }
This code will produce a list which contains the ElementId's of every type of wall my project has. The problem is that I cannot figure out how to cycle through each wall type and select all instances of it, or even how to check and see if there -are- any instances of it.
I would apprecciate any help on this, it has had me pulling my hair out all day. >_>
Solved! Go to Solution.