Using the lookup method to view materials can be quite misleading.
It took considerable time to identify the cause. To find all materials, you need to search through the Compound Structure Layers.
Please see the attached code demonstrating two ways to retrieve materials:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.ApplicationServices;
// Reading materials from the namespace
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.Attributes.Journaling(Autodesk.Revit.Attributes.JournalingMode.NoCommandData)]
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
public class Class1 : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
Document revitDoc = commandData.Application.ActiveUIDocument.Document; // Get the active document
Application revitApp = commandData.Application.Application; // Get the Revit application instance
UIDocument uiDoc = commandData.Application.ActiveUIDocument;
Selection sel = uiDoc.Selection;
Reference ref1 = sel.PickObject(ObjectType.Element, “Select a family instance”);
Element elem = revitDoc.GetElement(ref1);
Wall wall = elem as Wall;
ICollection<ElementId> matId = elem.GetMaterialIds(true);
#region Retrieve materials from ElementId (this method gets the main material)
//foreach (var item in matId)
//{
// TaskDialog.Show(“REVIT”, item.ToString());
// Material mat2 = revitDoc.GetElement(item) as Material; // Get material by ElementId
//}
// Location
#endregion
#region Retrieve materials from Compound Structure Layers (this method retrieves all materials related to the element)
WallType wallType = wall.WallType;
CompoundStructure compoundStructure = wallType.GetCompoundStructure();
IList<CompoundStructureLayer> layers = compoundStructure.GetLayers();
foreach (var item in layers)
{
TaskDialog.Show(“revit”, item.MaterialId.ToString());
}
// Location
#endregion
return Result.Succeeded;
}
}
}













Must log in before commenting!
Sign Up