Getting the area of all major faces of a host

In the last post where the user was prompted to select a single face to get its area. Building on that idea, this sample prompts the user to select a host element (wall, floor, roof, etc). Then it shows the areas of all major (side, top, and/or bottom faces).

For a wall, the interior and exterior faces are combined into a single list with the Concat method. For a floor or roof, Concat is used to create a single list with references to both the top and bottom faces.

public void areaHostMajorFaces()
{
    Document doc = this.Document;    
    UIDocument uidoc = new UIDocument(doc);
    Reference r = uidoc.Selection.PickObject(ObjectType.Element, "Select a face of a wall, roof, or floor");
    Element e = doc.GetElement(r);
    HostObject hostObj = e as HostObject;
    if (hostObj == null)
    {
        TaskDialog.Show("Error", "Element selected is not a host object");
        return;
    }

    IList<Reference> references = null;

    if (hostObj is Wall)
    {
        IList<Reference> exterior = HostObjectUtils.GetSideFaces(hostObj, ShellLayerType.Exterior);
        IList<Reference> interior = HostObjectUtils.GetSideFaces(hostObj, ShellLayerType.Interior);
        references = new List<Reference>(exterior.Concat(interior));
    }
    else if (hostObj is RoofBase || hostObj is Floor)
    {
        IList<Reference> top = HostObjectUtils.GetTopFaces(hostObj);
        IList<Reference> bottom = HostObjectUtils.GetBottomFaces(hostObj);
        references = new List<Reference>(top.Concat(bottom));
    }

    string areas = "Areas of faces of element '" + e.Name + "' (" + e.Id + ")\n";
    foreach (Reference myRef in references)
    {
        Face face = e.GetGeometryObjectFromReference(myRef) as Face;
        areas += face.Area + "\n";
    }
    TaskDialog.Show("Area", areas);
}
Advertisements

Getting the area of a single face

At “Revit in Plain English“, Jay mentions that Revit reports a single area value for a wall, but that he wants that actual area of a specific face.

Here is a quick document macro (not an application macro like in my other samples) to get the area of any face.

public void areaOneFace()
{
    Document doc = this.Document;    
    UIDocument uidoc = new UIDocument(doc);
    Reference myRef = uidoc.Selection.PickObject(ObjectType.Face, "Select a face");
    Element e = doc.GetElement(myRef);
    Face face = e.GetGeometryObjectFromReference(myRef) as Face;
    TaskDialog.Show("Area", "Area of face selected on element '" + e.Name + "' (" + e.Id + ")\n" + face.Area);
}

When the wall is attached to the roof so that the area of each side face is unique, the schedule reports the wall area as 619. With the macro we find that the area of each face is 618.52 and 568.08.