RVTDocs.com
Namespace: Autodesk.Revit.DB

Material

Class
Description:
Represents a material element within an Autodesk Revit project.
Inheritance Hierarchy:
System.Object
  Autodesk.Revit.DB.Element
    Autodesk.Revit.DB.Material
Syntax
public class Material : Element
Examples
private void GetMaterialInformation(Material material)
{
   StringBuilder message = new StringBuilder("Material : " + material.Name);
   //color of the material
   message.Append(string.Format("\nColor: Red[{0}]; Green[{1}]; Blue[{2}]",
                   material.Color.Red, material.Color.Green, material.Color.Blue));

   //foreground cut pattern and pattern color of the material
   FillPatternElement cutForegroundPattern = material.Document.GetElement(material.CutForegroundPatternId) as FillPatternElement;
   if (null != cutForegroundPattern)
   {
      message.Append("\nCut Foreground Pattern: " + cutForegroundPattern.Name);
      message.Append(string.Format("\nCut Foreground Pattern Color: Red[{0}]; Green[{1}]; Blue[{2}]",
                      material.CutForegroundPatternColor.Red, material.CutForegroundPatternColor.Green, material.CutForegroundPatternColor.Blue));
   }

   //foreground surface pattern and pattern color of the material
   FillPatternElement surfaceForegroundPattern = material.Document.GetElement(material.SurfaceForegroundPatternId) as FillPatternElement;
   if (null != surfaceForegroundPattern)
   {
      message.Append("\nSurface Foreground Pattern: " + surfaceForegroundPattern.Name);
      message.Append(string.Format("\nSurface Foreground Pattern Color: Red[{0}]; Green[{1}]; Blue[{2}]",
                      material.SurfaceForegroundPatternColor.Red, material.SurfaceForegroundPatternColor.Green, material.SurfaceForegroundPatternColor.Blue));
   }

   //background cut pattern and pattern color of the material
   FillPatternElement cutBackgroundPattern = material.Document.GetElement(material.CutBackgroundPatternId) as FillPatternElement;
   if (null != cutBackgroundPattern)
   {
      message.Append("\nCut Background Pattern: " + cutBackgroundPattern.Name);
      message.Append(string.Format("\nCut Background Pattern Color: Red[{0}]; Green[{1}]; Blue[{2}]",
                      material.CutBackgroundPatternColor.Red, material.CutBackgroundPatternColor.Green, material.CutBackgroundPatternColor.Blue));
   }

   //background surface pattern and pattern color of the material
   FillPatternElement surfaceBackgroundPattern = material.Document.GetElement(material.SurfaceBackgroundPatternId) as FillPatternElement;
   if (null != surfaceBackgroundPattern)
   {
      message.Append("\nSurface Background Pattern: " + surfaceBackgroundPattern.Name);
      message.Append(string.Format("\nSurface Background Pattern Color: Red[{0}]; Green[{1}]; Blue[{2}]",
                      material.SurfaceBackgroundPatternColor.Red, material.SurfaceBackgroundPatternColor.Green, material.SurfaceBackgroundPatternColor.Blue));
   }

   //some shading property of the material
   int shininess = material.Shininess;
   message.Append("\nShininess: " + shininess);
   int smoothness = material.Smoothness;
   message.Append("\nSmoothness: " + smoothness);
   int transparency = material.Transparency;
   message.Append("\nTransparency: " + transparency);

   TaskDialog.Show("Revit", message.ToString());
}