Material Class


Represents a material element within an Autodesk Revit project.

Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 19.0.0.0 (19.0.0.405)

Syntax

C#
public class Material : Element
Visual Basic
Public Class Material _
	Inherits Element
Visual C++
public ref class Material : public Element

Examples

Copy C#
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());
}
Copy VB.NET
Private Sub GetMaterialInformation(material As Material)
    Dim message As New StringBuilder("Material : " & Convert.ToString(material.Name))
    'color of the material
    message.Append(String.Format(vbLf & "Color: Red[{0}]; Green[{1}]; Blue[{2}]", material.Color.Red, material.Color.Green, material.Color.Blue))

    'foreground cut pattern and pattern color of the material
    Dim cutForegroundPattern As FillPatternElement = TryCast(material.Document.GetElement(material.CutForegroundPatternId), FillPatternElement)
    If cutForegroundPattern IsNot Nothing Then
        message.Append(vbLf & "Cut Foreground Pattern: " + cutForegroundPattern.Name)
        message.Append(String.Format(vbLf & "Cut Foreground Pattern Color: Red[{0}]; Green[{1}]; Blue[{2}]", material.CutForegroundPatternColor.Red, material.CutForegroundPatternColor.Green, material.CutForegroundPatternColor.Blue))
    End If

    'foreground surface pattern and pattern color of the material
    Dim surfaceForegroundPattern As FillPatternElement = TryCast(material.Document.GetElement(material.SurfaceForegroundPatternId), FillPatternElement)
    If surfaceForegroundPattern IsNot Nothing Then
        message.Append(vbLf & "Surface Foreground Pattern: " + surfaceForegroundPattern.Name)
        message.Append(String.Format(vbLf & "Surface Foreground Pattern Color: Red[{0}]; Green[{1}]; Blue[{2}]", material.SurfaceForegroundPatternColor.Red, material.SurfaceForegroundPatternColor.Green, material.SurfaceForegroundPatternColor.Blue))
    End If

    'background cut pattern and pattern color of the material
    Dim cutBackgroundPattern As FillPatternElement = TryCast(material.Document.GetElement(material.CutBackgroundPatternId), FillPatternElement)
    If cutBackgroundPattern IsNot Nothing Then
        message.Append(vbLf & "Cut Background Pattern: " + cutBackgroundPattern.Name)
        message.Append(String.Format(vbLf & "Cut Background Pattern Color: Red[{0}]; Green[{1}]; Blue[{2}]", material.CutBackgroundPatternColor.Red, material.CutBackgroundPatternColor.Green, material.CutBackgroundPatternColor.Blue))
    End If

    'background surface pattern and pattern color of the material
    Dim surfaceBackgroundPattern As FillPatternElement = TryCast(material.Document.GetElement(material.SurfaceBackgroundPatternId), FillPatternElement)
    If surfaceBackgroundPattern IsNot Nothing Then
        message.Append(vbLf & "Surface Background Pattern: " + surfaceBackgroundPattern.Name)
        message.Append(String.Format(vbLf & "Surface Background Pattern Color: Red[{0}]; Green[{1}]; Blue[{2}]", material.SurfaceBackgroundPatternColor.Red, material.SurfaceBackgroundPatternColor.Green, material.SurfaceBackgroundPatternColor.Blue))
    End If

    'some shading property of the material
    Dim shininess As Integer = material.Shininess
    message.Append(vbLf & "Shininess: " & shininess)
    Dim smoothness As Integer = material.Smoothness
    message.Append(vbLf & "Smoothness: " & smoothness)
    Dim transparency As Integer = material.Transparency
    message.Append(vbLf & "Transparency: " & transparency)

    TaskDialog.Show("Revit", message.ToString())
End Sub

Inheritance Hierarchy

See Also