DialogBoxShowing Event from an external command crashing revit on running addin

DialogBoxShowing Event from an external command crashing revit on running addin

Anonymous
Not applicable
1,127 Views
2 Replies
Message 1 of 3

DialogBoxShowing Event from an external command crashing revit on running addin

Anonymous
Not applicable

See the following

I am getting a complete crash of revit when i start the addin and it gets past the call to invoke a modal dialog. I f i dont include it nothing happens at all i dont get the taskdialog showing or anything.

 

//main external command

public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
//Get application and document objects
UIApplication uiApp = commandData.Application;
UIDocument uiDoc = uiApp.ActiveUIDocument;
Autodesk.Revit.ApplicationServices.Application app = uiApp.Application;
Autodesk.Revit.DB.Document doc = uiDoc.Document;



//calls to modal dialog

 

OnStartup(uiApp);

 

//do some stuff with postcommand

 

//Call to modless dialog

 

boiler code ....etc

}

 

 

 

 

// Implement the OnStartup method to register events when Revit starts.
public Result OnStartup(UIApplication application)
{
// Register related events
application.DialogBoxShowing +=
new EventHandler<Autodesk.Revit.UI.Events.DialogBoxShowingEventArgs>(AppDialogShowing);

TaskDialog.Show("dialog showing", "registered");

return Result.Succeeded;
}

// Implement this method to unregister the subscribed events when Revit exits.
public Result OnShutdown(UIApplication 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
public void AppDialogShowing(object sender, DialogBoxShowingEventArgs args)
{
TaskDialog.Show("x", "xxxxx");
}//end mthd

0 Likes
Accepted solutions (1)
1,128 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable

Also I added some send key calls, removed them, added a post command removed them, changed the calls to a true object not static class. I emptied out the event that gets raised as well. 

The only thing it does do is to sometimes report that the event has been registered from the command, going to try an external command next

Message 3 of 3

RPTHOMAS108
Mentor
Mentor
Accepted solution

OnStartup shouldn't be called again from the external command directly. OnStartup occurs when Revit starts and should not be revisited after this.

 

In your example the dialogue showing event is registered at start-up, then when you execute the command it tries to register it again (this will fail). Only when Revit closes the OnShutdown method is called to remove the handler.

 

I know that the .net framework doesn't like a handler for the same event being added twice without first removing it in-between. This isn't a Revit issue it is more general to .net. Although strangely in .net there appears to be no way of knowing if a handler is active for an event (from my exploring anyway).

 

 

0 Likes