DialogBoxShowing 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: 24.0.0.0 (24.0.0.0)
Since: 2010

Syntax

C#
public event EventHandler<DialogBoxShowingEventArgs> DialogBoxShowing
Visual Basic
Public Event DialogBoxShowing As EventHandler(Of DialogBoxShowingEventArgs)
Visual C++
public:
 event EventHandler<DialogBoxShowingEventArgs^>^ DialogBoxShowing {
	void add (EventHandler<DialogBoxShowingEventArgs^>^ value);
	void remove (EventHandler<DialogBoxShowingEventArgs^>^ value);
}

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.

Examples

Copy C#
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);
        }
    }
Copy VB.NET
Public Class Application_DialogBoxShowing
    Implements IExternalApplication
    ' Implement the OnStartup method to register events when Revit starts.
    Public Function OnStartup(application As UIControlledApplication) As Autodesk.Revit.UI.Result Implements IExternalApplication.OnStartup
        ' Register related events
        AddHandler application.DialogBoxShowing, AddressOf AppDialogShowing
        Return Result.Succeeded
    End Function

    ' Implement this method to unregister the subscribed events when Revit exits.
    Public Function OnShutdown(application As UIControlledApplication) As Autodesk.Revit.UI.Result Implements IExternalApplication.OnShutdown
        ' unregister events
        RemoveHandler application.DialogBoxShowing, AddressOf AppDialogShowing
        Return Result.Succeeded
    End Function

    ' The DialogBoxShowing event handler, which allow you to 
    ' do some work before the dialog shows
    Private Sub AppDialogShowing(sender As Object, args As DialogBoxShowingEventArgs)
        Dim tdEventArgs As TaskDialogShowingEventArgs = TryCast(args, TaskDialogShowingEventArgs)

        If tdEventArgs IsNot Nothing AndAlso tdEventArgs.DialogId = "TaskDialog_Really_Print_Or_Export_Temp_View_Modes" Then
            args.OverrideResult(CInt(TaskDialogResult.CommandLink2))
        End If
    End Sub
End Class

See Also