OfClass filter for ElectricalEquipment

OfClass filter for ElectricalEquipment

perry.lackowski
Participant Participant
290 Views
2 Replies
Message 1 of 3

OfClass filter for ElectricalEquipment

perry.lackowski
Participant
Participant

I had a function set up to automatically collect all the electrical equipment in the project. However, it's also collecting some DirectShape elements that are on the Electrical Equipment category, and this is problematic since I'm calling .MEPModel to access the electrical system on these elements. DirectShapes don't have this component, so I want to exclude them.

 

I tried adding a class filter but I can't manage to get it to work, since ElectricalEquipment is not a subtype of Element, but a subtype of MEPObject. It makes sense that this might throw an error since I'm using a filtered element collector, but it's also confusing, because you can still collect the electrical equipment if you just use the category filter without the class filter.

 

 

def get_electrical_equipment(sort_by_name = False):
    
    elements = DB.FilteredElementCollector(doc)\
        .OfCategory(DB.BuiltInCategory.OST_ElectricalEquipment)\
        .OfClass(DB.Electrical.ElectricalEquipment)\
        .WhereElementIsNotElementType()
    
    if sort_by_name:
        elements = list(elements)
        elements.sort(key=lambda x: x.Name)
    
    return elements

 

 

 

 

0 Likes
Accepted solutions (1)
291 Views
2 Replies
Replies (2)
Message 2 of 3

mhannonQ65N2
Collaborator
Collaborator
Accepted solution

You should use OfClass(DB.FamilyInstance) since family instances have the MEPModel property you are looking for.

Message 3 of 3

perry.lackowski
Participant
Participant
That seems to have solved it, thank you!
0 Likes