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.
Solved by jeremytammik. Go to Solution.
Becuase this will not only be for wall types, I'm going to be exporting all Categories in the project, so I need a flexible system that will be able to capture everything.
I've thought about just creating a separate method for each category (using somehting similar to what you suggessted in each method), and I'll go that route if it becomes necessary, but I'd prefer to be able to handle it with a single method if at all possible.
Try this:
WallType X; FilteredElementCollector allWallsOfTypeX = new FilteredElementCollector(doc) .OfClass(typeof(Wall)) .Where( e => e.WallType.Id.IntegerValue.Equals( X.Id.IntegerValue ) );
Cheers,
Jeremy
Hello,
The code that you have written works perfectly but what should I do to make all walls blue (i.e. selected ) through a C# code. I want to make a button, If I click on it all walls in the project must become blue(i.e. selected).
I don't know if that is possible through the API. The selecting color is something a user can set in the Revit options.
RefreshActiveView() method used after selecting all your walls would highlight your walls.