How to filter elements through the Tab?

How to filter elements through the Tab?

Anonymous
Not applicable
381 Views
2 Replies
Message 1 of 3

How to filter elements through the Tab?

Anonymous
Not applicable

The title is maybe a little confusing. For example, I had a List<Element> elements. As shown in the figure below, the System Tab owns various element types: HVAC type, Fabrication type, Mechanical type, Piping type, Electrical type. I need to classify the elements list by these types. Is there any method to implement this? Revit.png

 

 

 

0 Likes
382 Views
2 Replies
Replies (2)
Message 2 of 3

naveen.kumar.t
Autodesk Support
Autodesk Support

Use FilteredElementCollector to collect elements and get the type of the elements and with the help of the type classify the elements

 FilteredElementCollector Collector = new FilteredElementCollector(doc).WhereElementIsNotElementType();
                IList<ElementId> all_eids = Collector.ToElementIds() as IList<ElementId>;

                IList<ElementId> mech_ids = new List<ElementId>();
                IList<ElementId> elec_ids = new List<ElementId>();
                IList<ElementId> HVAC_ids = new List<ElementId>();
                IList<ElementId> piping_ids = new List<ElementId>();
                IList<ElementId> fabrication_ids = new List<ElementId>();

                foreach(ElementId eid in all_eids)
                {
                    Element e = doc.GetElement(eid);
                    Type T = e.GetType() as Type;
                    if(T.Name.Contains("Mechanical"))
                    {
                        mech_ids.Add(e.Id);
                    }
                    if(T.Name.Contains("Electrical"))
                    {
                        elec_ids.Add(e.Id);
                    }
                    if(T.Name.Contains("HVAC"))
                    {
                        HVAC_ids.Add(e.Id);
                    }
                    if(T.Name.Contains("Piping"))
                    {
                        piping_ids.Add(e.Id);
                    }
                    if(T.Name.Contains("Fabrication"))
                    {
                        fabrication_ids.Add(e.Id);
                    }

                }

Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 3

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @Anonymous,

You can also approach by using with the below code

 FilteredElementCollector mech_coll = new FilteredElementCollector(doc).OfClass(typeof(MechanicalSystem)).WhereElementIsNotElementType();
                IList<ElementId> mech_ids = mech_coll.ToElementIds() as IList<ElementId>;

Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes