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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s