Stackwd walls are walls made up of multiple wall types at different height. So, getting the compound structure of a stacked wallwill raise the question, "at what height". Assuming that you query a stacked wall by providing a height as a parameter, you can do this;
public void ExtractStackedWallStructure()
{
Wall wall = (Wall) doc.GetElement(uidoc.Selection.PickObject(ObjectType.Element, new WallSelectionFilter(), "Pick a stacked wall"));
double height = 6.5; // In feet
CompoundStructure compoundStructure = GetStackedWallCompoundStructure(wall, height);
IList<CompoundStructureLayer> layers = compoundStructure.GetLayers();
List<string> materialNames = new List<string>();
try {
foreach (CompoundStructureLayer layer in layers)
{
Material material = doc.GetElement(layer.MaterialId) as Material;
if (material != null)
{
materialNames.Add(material.Name);
}
}
TaskDialog.Show("Compound structure layers", materialNames[0]);
} catch (Exception e) {
throw e;
}
}
/// <summary>
///
/// </summary>
/// <param name="stackedWall"></param>
/// <param name="height"> This variable is to get the wall at the height provided</param>
/// <returns></returns>
private CompoundStructure GetStackedWallCompoundStructure(Wall stackedWall, double height = 0.0)
{
// The GetStackedWallMemberIds() method returns the element ids of the member walls of a stacked wall
if (stackedWall.IsStackedWall == false) return null;
List<Wall> walls = stackedWall.GetStackedWallMemberIds()
.Select(w => (Wall) doc
.GetElement(w))
.ToList();
// If height is zero, the first member wall's compound structure is returned
if (height - 0.0 < 0.00001)
{
WallType wallType = walls[0].WallType;
CompoundStructure co = wallType.GetCompoundStructure();
return co;
}
// return the wall type of the wall at the given height
foreach (Wall wall in walls)
{
double baseHeight = wall.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET).AsDouble();
double topHeight = baseHeight + wall.get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM).AsDouble();
if (height >= baseHeight && height <= topHeight)
{
WallType wallType = wall.WallType;
return wallType.GetCompoundStructure();
}
}
return null;
}
}
class WallSelectionFilter : ISelectionFilter
{
public bool AllowElement(Element elem)
{
Wall wall = elem as Wall;
if (wall == null){
return false;
}
return wall.IsStackedWall;
}
public bool AllowReference(Reference reference, XYZ position)
{
return false;
}
}
Here, the private method takes a height parameter, which in case not provided, will return the compound structure of the bottom most wall type.
Hope this helps.