You said "family". If you want to access to wall and roof, they have their own class, like Wall, Roof, Floor etc.
Here is the sample code.
I used the material name as "Wood" but you can change also If you know MaterialId which you want to take you can use it, If you don't know its Id you can snoop with Revit LookUp.
// This is the wood elements name list
string woodElementNames = "";
// Collect walls and floors in the document
List<Wall> walls = new FilteredElementCollector(doc).OfClass(typeof(Wall)).Cast<Wall>().ToList();
List<Floor> floors = new FilteredElementCollector(doc).OfClass(typeof(Floor)).Cast<Floor>().ToList();
List<FootPrintRoof> footPrintRoofs = new FilteredElementCollector(doc).OfClass(typeof(FootPrintRoof)).Cast<FootPrintRoof>().ToList();
List<ExtrusionRoof> extrusionRoofs = new FilteredElementCollector(doc).OfClass(typeof(ExtrusionRoof)).Cast<ExtrusionRoof>().ToList();
if (walls != null)
{
foreach (var wall in walls)
{
var wallLayers = wall.WallType.GetCompoundStructure().GetLayers();
foreach (var layer in wallLayers)
{
var material = doc.GetElement(layer.MaterialId) as Material;
// I typed material name wood, If yours are different type it.
if (layer.Function == MaterialFunctionAssignment.Structure && material.Name == "Wood")
{
woodElementNames += (wall.WallType.FamilyName +wall.WallType.Name + "\n");
}
}
}
}
if (floors != null)
{
foreach (var floor in floors)
{
// If you don't want to count paint material set to false
var materialIds = floor.GetMaterialIds(false);
foreach (var id in materialIds)
{
var material = doc.GetElement(id) as Material;
if (material.Name == "Wood")
{
woodElementNames += (floor.FloorType.FamilyName + floor.FloorType.Name + "\n");
}
}
}
}
if (footPrintRoofs != null)
{
foreach (var roof in footPrintRoofs)
{
var materialIds = roof.GetMaterialIds(false);
foreach (var id in materialIds)
{
var material = doc.GetElement(id) as Material;
if (material.Name == "Wood")
{
woodElementNames += (roof.Name + "\n");
}
}
}
}
if (extrusionRoofs != null)
{
foreach (var roof in extrusionRoofs)
{
var materialIds = roof.GetMaterialIds(false);
foreach (var id in materialIds)
{
var material = doc.GetElement(id) as Material;
if (material.Name == "Wood")
{
woodElementNames += (roof.Name + "\n");
}
}
}
}
TaskDialog.Show("Wood Elements", woodElementNames);
I know the code is not looking clear, I pasted it from visual studio and everythin is a mess now 🙂
I tested and worked fine for me, I hope this works for you too.
Recep.