How to retrieve the openings of Wall (not the coordinates)?

518 views Asked by At

I have retreive the levels as treeview(List of levels in treeview in WPF form) and then selected a wall(e.g xyz_wall) from a specific level(e.g. Level1) in Revit project, I want to retrieve the list openings(doors and windows) of selected wall and show to the message box (in message box-list of openings:).

1

There are 1 answers

0
user3493725 On

Window and Doors are FamilyInstances, and an Opening cut through a wall is an Opening object.

private IList<Element> GetHostedElements(Wall wall)
{
    Document doc = wall.Document;
    
    ElementId id = wall.Id;
    
    IList<Element> result = new List<Element>();

    IEnumerable<Opening> openingInstances =
        new FilteredElementCollector(doc)
            .OfClass(typeof(Opening))
            .WhereElementIsNotElementType()
            .Cast<Opening>();

    foreach (Opening openingInstance in openingInstances)
    {
        if (openingInstance.Host.Id.Equals(id))
        {
            result.Add(openingInstance);
        }
    }

    IEnumerable<FamilyInstance> familyInstances =
        new FilteredElementCollector(doc)
            .OfClass(typeof(FamilyInstance))
            .WhereElementIsNotElementType()
            .Cast<FamilyInstance>();
                
    foreach (FamilyInstance familyInstance in familyInstances)
    {
        if (familyInstance.Host.Id.Equals(id))
        {
            result.Add(familyInstance);
        }
    }
    
    return result;          
}