CompoundStructure

CompoundStructure

Walls, floors, ceilings and roofs are all children of the API class HostObject. HostObject (and its related type class HostObjAttributes) provide read only access to the CompoundStructure.

The CompoundStructure class offers read and write access to a set of layers consisting of different materials:

Normally these layers are parallel and extend the entire host object with a fixed layer width. However, for walls the structure can also be “vertically compound”, where the layers vary at specified vertical distances from the top and bottom of the wall. Use CompoundStructure.IsVerticallyCompound to identify these. For vertically compound structures, the structure describes a vertical section via a rectangle which is divided into polygonal regions whose sides are all vertical or horizontal segments. A map associates each of these regions with the index of a layer in the CompoundStructure which determines the properties of that region.

It is possible to use the compound structure to find the geometric location of different layer boundaries. The method CompoundStructure.GetOffsetForLocationLine() provides the offset from the center location line to any of the location line options (core centerline, finish faces on either side, or core sides).

With the offset to the location line available, you can obtain the location of each layer boundary by starting from a known location and obtaining the widths of each bounding layer using CompoundStructure.GetLayerWidth().

Some notes about the use of CompoundStructure:

Material

Each CompoundStructureLayer in HostObjAttributes is typically displayed with some type of material. If CompoundStructureLayer.MaterialId returns -1, it means the Material is Category-related. For more details, refer to Material. Getting the CompoundStructureLayer Material is illustrated in the following sample code:

Code Region 11-5: Getting the CompoundStructureLayer Material

public void GetWallLayerMaterial(Autodesk.Revit.DB.Document document, Wall wall)
{
        // get WallType of wall
        WallType aWallType = wall.WallType;
        // Only Basic Wall has compoundStructure
        if (WallKind.Basic == aWallType.Kind)
        {

                // Get CompoundStructure
                CompoundStructure comStruct = aWallType.GetCompoundStructure();
                Categories allCategories = document.Settings.Categories;

                // Get the category OST_Walls default Material; 
                // use if that layer's default Material is <By Category>
                Category wallCategory = allCategories.get_Item(BuiltInCategory.OST_Walls);
                Autodesk.Revit.DB.Material wallMaterial = wallCategory.Material;

                foreach (CompoundStructureLayer structLayer in comStruct.GetLayers())
                {
                        Autodesk.Revit.DB.Material layerMaterial = 
                                document.GetElement(structLayer.MaterialId) as Material;

                        // If CompoundStructureLayer's Material is specified, use default
                        // Material of its Category
                        if (null == layerMaterial)
                        {
                                switch (structLayer.Function)
                                {
                                        case MaterialFunctionAssignment.Finish1:
                                                layerMaterial =                                       
                                                        allCategories.get_Item(BuiltInCategory.OST_WallsFinish1).Material;
                                                break;
                                        case MaterialFunctionAssignment.Finish2:
                                                layerMaterial =                                      
                                                        allCategories.get_Item(BuiltInCategory.OST_WallsFinish2).Material;
                                                break;
                                        case MaterialFunctionAssignment.Membrane:
                                                layerMaterial =
                                                        allCategories.get_Item(BuiltInCategory.OST_WallsMembrane).Material;
                                                break;
                                        case MaterialFunctionAssignment.Structure:
                                                layerMaterial =  
                                                        allCategories.get_Item(BuiltInCategory.OST_WallsStructure).Material;
                                                break;
                                        case MaterialFunctionAssignment.Substrate:
                                                layerMaterial = 
                                                        allCategories.get_Item(BuiltInCategory.OST_WallsSubstrate).Material;
                                                break;
                                        case MaterialFunctionAssignment.Insulation:
                                                layerMaterial = 
                                                        allCategories.get_Item(BuiltInCategory.OST_WallsInsulation).Material;
                                                break;
                                        default:
                                                // It is impossible to reach here
                                                break;
                                }
                                if (null == layerMaterial)
                                {
                                        // CompoundStructureLayer's default Material is its SubCategory
                                        layerMaterial = wallMaterial;
                                }
                        }
                        TaskDialog.Show("Revit","Layer Material: " + layerMaterial);
                }
        }
}

Sometimes just the material from the "structural" layer is needed. Rather than looking at each layer for the one whose function is MaterialFunctionAssignment.Structure, use the CompoundStructure.StructuralMaterialIndex property to find the index of the layer whose material defines the structural properties of the type for the purposes of analysis.