If there is no pure API solution, you can "drive"the dialog using UIAutomation
Add the following references to your rpoject:
UIAutomationClient, UIAutomationClientsideProviders, UIAutomationProvider and UIAutomationTypes.
You can track changes of focus by subscribing to the AutomationFocusChangedEvent. This is a systemwide event, so even changes to other processes will be reported. Once you find the (focussed) OK-Button of the dialog, you can "press" it programmaticly.
//using System.Windows.Automation;
public class Main_Proc : IExternalApplication
{
private AutomationFocusChangedEventHandler focusHandler = null;
private int thisProcessId;
public Autodesk.Revit.UI.Result OnStartup(UIControlledApplication application)
{
thisProcessId = System.Diagnostics.Process.GetCurrentProcess().Id;
focusHandler = new AutomationFocusChangedEventHandler(OnFocusChange);
Automation.AddAutomationFocusChangedEventHandler(focusHandler);
return Result.Succeeded;
}
/// <summary>
/// Handle the event.
/// </summary>
/// <param name="src">Object that raised the event.</param>
/// <param name="e">Event arguments.</param>
private void OnFocusChange(object src, AutomationFocusChangedEventArgs e)
{
AutomationElement source = src as AutomationElement;
if (source == null) return;
if (source.Current.ProcessId != thisProcessId) return; // the eventhandler reacts to systemwide events => check for current process.
if (source.Current.Name != "OK") return; // the OK-button of the dialog has focus initially. the string might be language dependent
// find the dialog-form
TreeWalker walker = TreeWalker.ControlViewWalker;
AutomationElement parent = walker.GetParent(source);
if (parent == null) return;
if (parent.Current.ClassName != "#32770") return; // the dialog-form has a specific class, value for Revit 2019, might be different for other versions
if (parent.Current.Name != "Autodesk Revit 2019") return; // the dialog-form has a specific Caption, might be language dependent, is version dependent
// right button on the right dialog-form => "click" button
Object invPattern;
if (source.TryGetCurrentPattern(InvokePattern.Pattern, out invPattern))
{
(invPattern as InvokePattern).Invoke();
}
}
public Autodesk.Revit.UI.Result OnShutdown(UIControlledApplication application)
{
if (focusHandler != null)
{
Automation.RemoveAutomationFocusChangedEventHandler(focusHandler);
}
return Result.Succeeded;
}
}