DialogBoxShowing event not firing when model is opened.

DialogBoxShowing event not firing when model is opened.

Anonymous
Not applicable
739 Views
3 Replies
Message 1 of 4

DialogBoxShowing event not firing when model is opened.

Anonymous
Not applicable

After smashing my face against this problem and pouring through the API documentation/building coder blog I'm stumped. I can't get the DialogBoxShowing event to fire while opening a document, either manually or via the API. Note that this is very similar to the problem mentioned here: http://forums.autodesk.com/t5/revit-api/dialogboxshowing-event-not-firing-when-model-is-opened/m-p/5... If I'm reading the answer correctly, the problem could not be reproduced, so I've tried to boil the problem down to a few simple reproducible steps. 

 

Steps:

1. Create a new RVT file.

2. Create a new blank DWG file.

3. Link the DWG file into the RVT file, you will get a warning "Import detected no valid elements in the file's Model space. Do you want to import from the Paper space?" This will also trigger the DialogBoxShowing event.

4. Save the RVT and close.

5. Open the RVT file you just created. You'll get the same warning, but no event will trigger.

6. Run the code below, using OpenDoucmentFile. Same thing, warning, no event.

 

Here is the code I am also using to reproduce this behavior:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Autodesk.Revit;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Events;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Events;
using System.Management;

namespace Dialog
{
    [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
    [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Automatic)]

    public class Class1 : IExternalApplication
    {
        public Autodesk.Revit.UI.Result OnStartup(UIControlledApplication application)
        {
            MessageBox.Show("Registering event handler");
                application.DialogBoxShowing += new EventHandler<DialogBoxShowingEventArgs>(HandleDialogBoxShowing);
                application.ControlledApplication.ApplicationInitialized += new EventHandler<ApplicationInitializedEventArgs>(appinitialized);
                return Result.Succeeded;
        }
        public static void HandleDialogBoxShowing(object sender, Autodesk.Revit.UI.Events.DialogBoxShowingEventArgs dialogargs)
        {
            TaskDialogShowingEventArgs taskargs = dialogargs as TaskDialogShowingEventArgs;
            MessageBox.Show("Dialog about to show.");
        }
        public static void appinitialized(object sender, ApplicationInitializedEventArgs e)
        {
            Document doc = null;
            Autodesk.Revit.ApplicationServices.Application applin = sender as Autodesk.Revit.ApplicationServices.Application;
            UIApplication uiApp = new UIApplication(applin);
            doc = uiApp.Application.OpenDocumentFile(@"C:\not showing.rvt");
        }
        public Autodesk.Revit.UI.Result OnShutdown(UIControlledApplication application)
        {
            return Autodesk.Revit.UI.Result.Succeeded;
        }

    }
}

I would really like to be able to handle this message but I can't get the event to trigger. Is this intended behavior? Any work around anyone has come across?

0 Likes
740 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

I'm using a similar handler and it works. The code is different than yours. I sort of recall starting out like yours but having do write it this way. Notice the "ControlledApplication" between the "a" and the "DocumentOpened" event name. Your code is missing that. Maybe that is what is wrong?

 

 public Result OnStartup(UIControlledApplication a) {
            _app = this;
            AddBeThisTo_WTA_Ribbon(a);

            /// Subscribe to doc open event so that a user set
            /// default workset can be set
            a.ControlledApplication.DocumentOpened +=
            new EventHandler<DocumentOpenedEventArgs>(a_DocumentOpened);
            return Result.Succeeded;
        }
0 Likes
Message 3 of 4

Anonymous
Not applicable

Sorry, ignore what I posted. The DialogBoxShowing event is not at the ControlledApplication.

Message 4 of 4

Anonymous
Not applicable

Thank you for trying. I hope this thread at least caught the attention of someone who can log it as a bug. 

0 Likes