IExportContextOnElementBegin Method

This method marks the beginning of an element to be exported.

Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 25.0.0.0 (25.0.0.0)
Syntax
RenderNodeAction OnElementBegin(
	ElementId elementId
)

Parameters

elementId  ElementId
The Id of the element that is about to be processed.

Return Value

RenderNodeAction
Return RenderNodeAction.Skip if you wish to skip exporting this element, or return RenderNodeAction.Proceed otherwise.
Remarks
This method is never called for 2D export (see cref="Autodesk::Revit::DB::IExportContext2D").
Example
/// <summary>
/// Often it is found beneficial to keep a stack of th element(s)
/// currently being processed, so it can be refer to it from other
/// methods of the export context.
/// </summary>
Stack<ElementId> m_elementStack = new Stack<ElementId>();

ElementId CurrentElementId()
{
   return (m_elementStack.Count > 0) ? m_elementStack.Peek() : ElementId.InvalidElementId;
}

/// <summary>
/// Method that indicates the start of processing an element.
/// </summary>
public RenderNodeAction OnElementBegin(ElementId elementId)
{
   // We may find it useful to remember this element's Id.
   // So we can refer to it in methods invoked during the 
   // export process of this element
   m_elementStack.Push(elementId);

   // We can use the element's Id to find out more about the element being processed.
   // For example, we can test if the element is a wall; if it is, we can get more
   // information about the wall and then we can proceed with the export, which will 
   // continue with processing geometry of the element. Elements that are not wall
   // will be skipped.

   Wall theWall = m_document.GetElement(elementId) as Wall;
   if (theWall != null)
   {
      double wallVolume = theWall.get_Parameter(BuiltInParameter.HOST_VOLUME_COMPUTED).AsDouble();
      return RenderNodeAction.Proceed;
   }
   else
   {
      return RenderNodeAction.Skip;
   }
}

/// <summary>
/// Method that indicates the end of processing an element
/// </summary>
public void OnElementEnd(ElementId elementId)
{
   // Note: this method is invoked even for elements that were skipped.

   m_elementStack.Pop();
}
See Also