DialogBoxShowing Event


UIControlled Application Dialog Box Showing Event

Subscribe to the DialogBoxShowing event to be notified when Revit is just about to show a dialog box or a message box.

Namespace: Autodesk.Revit.UI
Assembly: RevitAPIUI (in RevitAPIUI.dll) Version: 25.0.0.0 (25.0.0.0)
Syntax
public event EventHandler<DialogBoxShowingEventArgs> DialogBoxShowing

Value

EventHandler DialogBoxShowingEventArgs
Remarks

This event is raised when Revit is just about to show a dialog box or a message box.

Event is not cancellable. The 'Cancellable' property of event's argument is always False.

Depending on the type of the dialog that is being shown, the event's argument's type varies as follows: When it is a dialog box, the event's argument is an object of DialogBoxShowingEventArgs . When it is a message box, the event's argument is an object of MessageBoxShowingEventArgs ,which is subclass of DialogBoxShowingEventArgs. When it is a task dialog, the event's argument is an object of TaskDialogShowingEventArgs ,which is subclass of DialogBoxShowingEventArgs.

No document may be modified during this event.

The following API functions are not available for the current document during this event:

Exception InvalidOperationException will be thrown if any of the above methods is called during this event.

Example
public class Application_DialogBoxShowing : IExternalApplication
{
    // Implement the OnStartup method to register events when Revit starts.
    public Result OnStartup(UIControlledApplication application)
    {
        // Register related events
        application.DialogBoxShowing +=
            new EventHandler<Autodesk.Revit.UI.Events.DialogBoxShowingEventArgs>(AppDialogShowing);
        return Result.Succeeded;
    }

    // Implement this method to unregister the subscribed events when Revit exits.
    public Result OnShutdown(UIControlledApplication application)
    {
        // unregister events
        application.DialogBoxShowing -=
            new EventHandler<Autodesk.Revit.UI.Events.DialogBoxShowingEventArgs>(AppDialogShowing);
        return Result.Succeeded;
    }

    // The DialogBoxShowing event handler, which allow you to 
    // do some work before the dialog shows
    void AppDialogShowing(object sender, DialogBoxShowingEventArgs args)
    {
        // check if the dialog is the "Export with Temporary Hide/Isolate dialog
        if (args is TaskDialogShowingEventArgs tdEventArgs &&
            tdEventArgs.DialogId == "TaskDialog_Really_Print_Or_Export_Temp_View_Modes")
        {
            // dismiss the dialog by selecting the 2nd option in the dialog
            // "Leave the mode on and export"
            args.OverrideResult((int)TaskDialogResult.CommandLink2);
        }
    }
See Also