Revit 2025 API
Compound |
Id of the material assigned to this layer.
Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 25.0.0.0 (25.0.0.0)
Syntax
public ElementId MaterialId { get; set; }
Public Property MaterialId As ElementId Get Set
public: property ElementId^ MaterialId { ElementId^ get (); void set (ElementId^ value); }
member MaterialId : ElementId with get, set
Property Value
ElementIdThe default is InvalidElementId.
| Exception | Condition |
|---|---|
| ArgumentNullException | When setting this property: A non-optional argument was null |
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); } } }
Public Sub GetWallLayerMaterial(document As Autodesk.Revit.DB.Document, wall As Wall) ' get WallType of wall Dim aWallType As WallType = wall.WallType ' Only Basic Wall has compoundStructure If WallKind.Basic = aWallType.Kind Then ' Get CompoundStructure Dim comStruct As CompoundStructure = aWallType.GetCompoundStructure() Dim allCategories As Categories = document.Settings.Categories ' Get the category OST_Walls default Material; ' use if that layer's default Material is <By Category> Dim wallCategory As Category = allCategories.Item(BuiltInCategory.OST_Walls) Dim wallMaterial As Autodesk.Revit.DB.Material = wallCategory.Material For Each structLayer As CompoundStructureLayer In comStruct.GetLayers() Dim layerMaterial As Autodesk.Revit.DB.Material = TryCast(document.GetElement(structLayer.MaterialId), Material) ' If CompoundStructureLayer's Material is specified, use default ' Material of its Category If layerMaterial Is Nothing Then Select Case structLayer.[Function] Case MaterialFunctionAssignment.Finish1 layerMaterial = allCategories.Item(BuiltInCategory.OST_WallsFinish1).Material Exit Select Case MaterialFunctionAssignment.Finish2 layerMaterial = allCategories.Item(BuiltInCategory.OST_WallsFinish2).Material Exit Select Case MaterialFunctionAssignment.Membrane layerMaterial = allCategories.Item(BuiltInCategory.OST_WallsMembrane).Material Exit Select Case MaterialFunctionAssignment.[Structure] layerMaterial = allCategories.Item(BuiltInCategory.OST_WallsStructure).Material Exit Select Case MaterialFunctionAssignment.Substrate layerMaterial = allCategories.Item(BuiltInCategory.OST_WallsSubstrate).Material Exit Select Case MaterialFunctionAssignment.Insulation layerMaterial = allCategories.Item(BuiltInCategory.OST_WallsInsulation).Material Exit Select Case Else ' It is impossible to reach here Exit Select End Select If layerMaterial Is Nothing Then ' CompoundStructureLayer's default Material is its SubCategory layerMaterial = wallMaterial End If End If TaskDialog.Show("Revit", "Layer Material: " & layerMaterial.ToString()) Next End If End Sub
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
See Also