Revit 2025 API
IExport |
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 )
Sub OnMaterial ( node As MaterialNode )
void OnMaterial( MaterialNode^ node )
abstract OnMaterial : node : MaterialNode -> unit
Parameters
- node MaterialNode
- A node describing the current material.

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(); } } }
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
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