Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
preynoldsarch
6394 Views, 7 Replies

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

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

7 REPLIES 7
Message 2 of 8

Why don't you use
FilteredElementCollector AllWallsTypes = new FilteredElementCollector(doc).OfClass(typeof(WallType));
Kind regards,
Remy van den Bor
ICN Solutions B.V.
Liked this post or found it usefull, don't forget the Kudo It won't hurt (at least not me).
Message 3 of 8

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.

Message 4 of 8

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
harish22
in reply to: jeremytammik

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

Message 6 of 8
R.van.den.Bor
in reply to: harish22

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

Kind regards,
Remy van den Bor
ICN Solutions B.V.
Liked this post or found it usefull, don't forget the Kudo It won't hurt (at least not me).
Message 7 of 8
wspratlen
in reply to: R.van.den.Bor

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

Message 8 of 8
adam.krug
in reply to: harish22

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community