OnMaterial Method


This method marks a change of the material.

Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 2015.0.0.0 (2015.0.0.0)
Since: 2014

Syntax

C#
void OnMaterial(
	MaterialNode node
)
Visual Basic
Sub OnMaterial ( _
	node As MaterialNode _
)
Visual C++
void OnMaterial(
	MaterialNode^ node
)

Parameters

node
Type: Autodesk.Revit.DB MaterialNode
A node describing the current material.

Examples

Copy C#
ElementId currentMaterialId = ElementId.InvalidElementId;
Color currentColor = new Color(0,0,0);
double currentTransparency = 0;
Asset currentAppearance = null;

/// <summary>
/// This code demonstrates how to process material information
/// </summary>
/// <remarks>
/// OnMaterial method can be invoked for every single out-coming mesh
/// even when the material has not actually changed. Thus it is usually
/// beneficial to store the current material and only get its attributes
/// when the material actually changes.
/// </remarks>
public void OnMaterial(MaterialNode node)
{
   // acquire properties of the material if it is different
   // than the material we have set as the currently applicable
   if (currentMaterialId != node.MaterialId)
   {
      if (node.MaterialId != ElementId.InvalidElementId)
      {
         currentColor = node.Color;
         currentTransparency = node.Transparency;
      }
      else
      {
         // the default material is being used in this case
      }

      // Appearance Asset is mainly for Revit internal use. However, if it is utilized 
      // in the export context, it needs to be checked whether or not the asset of the 
      // material is overridden by some local modification (e.g. by applying a decal)

      if (node.HasOverriddenAppearance)
      {
         currentAppearance = node.GetAppearanceOverride();
      }
      else
      {
         currentAppearance = node.GetAppearance();
      }
   }
}
Copy VB.NET
Private currentMaterialId As ElementId = ElementId.InvalidElementId
Private currentColor As New Color(0, 0, 0)
Private currentTransparency As Double = 0
Private currentAppearance As Asset = Nothing

' <summary>
' This code demonstrates how to process material information
' </summary>
' <remarks>
' OnMaterial method can be invoked for every single out-coming mesh
' even when the material has not actually changed. Thus it is usually
' beneficial to store the current material and only get its attributes
' when the material actually changes.
' </remarks>
Public Sub OnMaterial(node As MaterialNode) Implements IExportContext.OnMaterial
    ' acquire properties of the material if it is different
    ' than the material we have set as the currently applicable
    If currentMaterialId <> node.MaterialId Then
        If node.MaterialId <> ElementId.InvalidElementId Then
            currentColor = node.Color
            currentTransparency = node.Transparency
            ' the default material is being used in this case
        Else
        End If

        ' Appearance Asset is mainly for Revit internal use. However, if it is utilized 
        ' in the export context, it needs to be checked whether or not the asset of the 
        ' material is overridden by some local modification (e.g. by applying a decal)


        If node.HasOverriddenAppearance Then
            currentAppearance = node.GetAppearanceOverride()
        Else
            currentAppearance = node.GetAppearance()
        End If
    End If
End Sub

See Also

ArchiLabs

Stop fighting Revit automation.

Build repeatable BIM design and documentation workflows with scripts, data, and AI in one place, without wrestling brittle one-off automations.

Try ArchiLabs →