Selecting all instances of a wall (Or, are there any instances in the project?)

Selecting all instances of a wall (Or, are there any instances in the project?)

Anonymous
Not applicable
7,539 Views
7 Replies
Message 1 of 8

Selecting all instances of a wall (Or, are there any instances in the project?)

Anonymous
Not applicable

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. >_>

0 Likes
Accepted solutions (1)
7,540 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable
Why don't you use
FilteredElementCollector AllWallsTypes = new FilteredElementCollector(doc).OfClass(typeof(WallType));
Message 3 of 8

Anonymous
Not applicable

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.

0 Likes
Message 4 of 8

jeremytammik
Autodesk
Autodesk
Accepted solution

Try this:

 

WallType X;

FilteredElementCollector allWallsOfTypeX
  = new FilteredElementCollector(doc)
    .OfClass(typeof(Wall))
    .Where( e => e.WallType.Id.IntegerValue.Equals( 
      X.Id.IntegerValue ) );

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 5 of 8

Anonymous
Not applicable

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).

0 Likes
Message 6 of 8

Anonymous
Not applicable

I don't know if that is possible through the API. The selecting color is something a user can set in the Revit options.

0 Likes
Message 7 of 8

Anonymous
Not applicable

RefreshActiveView() method used after selecting all your walls would highlight your walls.

0 Likes
Message 8 of 8

adam.krug
Advocate
Advocate

commandData.Application.ActiveUIDocument.Selection.SetElementIds(my < ElementId > list);

0 Likes