Application: ContextMenu
Revit Platform: All
Revit Version: 2025.0
First Released For: 2025.0
Programming Language: C#
Skill Level: Beginning
Category: UI
Type: ExternalApplication

Subject: Create customized ContextMenu by ContextMenu API
Summary: 
This sample demonstrates how to create customized context menu for Add-In and how to create different types of menu items (CommandMenuItem, SeparatorItem, SubMenuItem).

Classes: 
Autodesk.Revit.UI.ContextMenu
Autodesk.Revit.UI.IContextMenuCreator
Autodesk.Revit.UI.IExternalCommand 
Autodesk.Revit.UI.IExternalApplication

Project Files: 
ContextMenu.cs
This file contains the class ContextMenuApplication which inherited from interface IExternalApplication and implemented method OnStartUp. The class will register user implemented context menu creator into application. 

AddInCommands.cs
This file contains the class ShowSelection which inherited from interface IExternalCommand and IExternalCommandAvailability, define the command will be executed when click item on context menu.

ContexMenuCreator.cs 
This file contains the class ContextMenuCreator which inherited from interface IContextMenuCreator, build the context menu and add menu item in it.

Description 
This sample should provide the following functionalities:
·	Build context menu by different items and register it into Revit.

Implementation Notes
·	To add ContextMenu in Revit, user need to implement the IExternalApplication interface, and call RegisterContextMenu method to register context menu creator in OnStartup(ControlledApplication) method.
·	To build ContextMenu, user need to implement the IContextMenuCreator interface, add menu items to the context menu passed in.
·	Each CommandMenuItem in ContextMenu should have a corresponding command to execute. The command corresponding to each CommandMenuItem should implement the IExternalCommand interface.
·	Use new ContextMenu() to create a new sub menu.
·	Use ContextMenu.AddItem() to add a single item to context menu.

Instructions: 
1.	Copy .addin file to the corresponding Addins folder for the Revit. You can find out the location of this folder by RevitAddUtility.dll, we also provided a sample named ExternalCommand for it.
    (For example, folder location for XP user is here: \\Documents and Settings\All Users\Application Data\Autodesk\Revit\Addins\2012)
2.	Copy the ContextMenu.dll to the same directory of this sample dll.
3.	Run Revit, right click the element on Canvas/ProjectBrowser, then you can see the customized ContextMenu in Revit. 
4.	Click each item to run this sample.