Application: DuplicateGraphics
Revit Platform: All
Revit Version: 2018.0
First Released For: 2018.0
Programming Language: C#
Skill Level: High
Category: Basics, Geometry
Type: ExternalCommand and ExternalApplication

Subject: Display graphics using DirectContext3D
Summary: 
The sample demonstrates basic usage of DirectContext3D. The external application creates DirectContext3D servers that extract geometry from selected Revit elements, encode it in pairs of vertex and index buffers, and submit it for rendering using DirectContext3D. The effect of the process, which is triggered using an ExternalCommand, is to display the geometry content of selected Revit elements at an offset, so that the graphics appear to be duplicated.

Classes:
Autodesk.Revit.DB.ExternalService.IExternalApplication
Autodesk.Revit.UI.IExternalCommand
Autodesk.Revit.DB.DirectContext3D.IDirectContext3DServer
Autodesk.Revit.DB.DirectContext3D.DrawContext

Project Files: 
Application.cs
The Application class derived from IExternalApplication creates and registers DirectContext3D servers that serve external geometry to Revit.
Command.cs
Two command classes derived from IExternalCommand provide an interface to the Application. The command class CommandDuplicateGraphics instructs the Application to prompt the user to select the Revit elements for processing. The command class CommandClearExternalGraphics instructs the Application to remove the DirectContext3D graphics that have been created.
RevitElementDrawServer.cs
The file contains the class RevitElementDrawServer that implements the IDirectContext3DServer interface. The server class extracts geometry from Revit elements and submits it for rendering using DirectContext3D.DrawContext.

Description: 
The sample shows how to use DirectContext3D to draw geometry, which is taken from existing Revit elements. The geometry is encoded in pairs of vertex and index buffers. Different types of geometry are prepared for different display styles, so that the graphical content of selected Revit elements appears to be duplicated in the same display style as the rest of the Revit view.

Instructions: 
Open Revit application and execute the command “Display graphics using DirectContext3D”.
1.	Select the elements whose graphics should be redrawn using DirectContext3D.
2.	Finish selection.
Expected result: Selected graphics will appear to be duplicated at an offset.
3.	Change the display style of the view.
Expected result: DirectContext3D graphics will change to match the display style.