Register application level event handlers in Dynamo. Specifically DialogBoxShowing

I am trying to register an event handler for DialogBoxShowing from within the Dynamo context with Zero Touch. Registering in Revit before opening Dynamo works fine but if I create a node that registers with the event handler it fails at run time. How would I subscribe to DialogBoxShowing from within Dynamo context? Here is one of many things I have tried:

I pass the Dynamo Revit>Document node into this but cannot get it to reference UIControlledApplication from within the function.

public static void RegisterEventHandler(Revit.Application.Document doc) { // I need to unwrap the document passed from the node but no "internal" method using (Transaction transaction = new Transaction(doc)) { transaction.Start("Register DialogBoxShowing event."); UIControlledApplicationuiapp = new UIControlledApplication(doc.Application); uiapp.DialogBoxShowing += new EventHandler( delegate (object sender, DialogBoxShowingEventArgs e) { TaskDialogShowingEventArgs e2 = e as TaskDialogShowingEventArgs; if (null != e2 && e2.DialogId.Equals( "TaskDialog_Really_Print_Or_Export_Temp_View_Modes")) { e.OverrideResult((int)TaskDialogResult.CommandLink1); } }); transaction.Commit(); } }
Looking around the libraries I found Autodesk.Revit.ApplicationServices.Application and Autodesk.Revit.ApplicationServicesControlledApplication and Autodesk.Revit.DB.Events which seem to be what I'm looking for but are of no use as far as I can tell (no unwrap method)
1 Like