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: 

OfClass filter for ElectricalEquipment

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
perry.lackowski
144 Views, 2 Replies

OfClass filter for ElectricalEquipment

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

 

 

 

 

Labels (1)
2 REPLIES 2
Message 2 of 3

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

Message 3 of 3

That seems to have solved it, thank you!

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

Post to forums  

Forma Design Contest


Rail Community