OnMaterial Method


IExport Context On Material Method

This method marks a change of the material.

Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 25.0.0.0 (25.0.0.0)
Syntax
void OnMaterial(
	MaterialNode node
)

Parameters

node MaterialNode
A node describing the current material.
Example
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();
      }
   }
}
See Also
ArchiLabs Desktop

Put AI to work inside Revit.

Give Desktop your instructions and project files to build Revit families, update model elements, and create views and schedules. Works directly in Revit and AutoCAD.

Explore Desktop →