[QUOTE=bryceclark;10079]I’m using C# to let the user choose series of Maya(.mb) files to run batch actions on. The tool launches a Maya process with a start-up command that sources a MEL script and waits for Maya to exit before launching the next maya file. The MEL script then handles all the actions and exits.
The problem with this system is that these particular files are triggering an error dialog that requires the user to click “Ok” before it finishes it’s start up initialization and script sourcing. So the user has to baby-sit the process to get past the dialog.
Is there a good way to catch and exit, or just bypass, these incidental, automation blocking, dialogs? In this case, it’s not possible/practical to try and fix the source of the error.[/QUOTE]
If a quick, less-than-elegant solution is acceptable, you can use AutoHotKey (http://www.autohotkey.com). AHK is free and relatively easy to pick up. Also, AHK scripts can be compiled into stand-alone executables (making it possible to run AHK scripts sans an AHK installation).
The code for such a script would look something like the following (the bulk of the following code snippet is comprised of comments, making it look far more complicated at first glance than it actually is):
"
/*
This example script waits for the “Delete Multiple Items” dialog to appear. This dialog is triggered by R-clicking on the recycling bin and selecting
the “Empty Recycling Bin” option from the context menu. Once the menu is detected, the script “hits” the “No” button in the dialog (thus closing it out
and cancelling the operation).
*/
/*
wait for and cancel 2 occurrences of the dialog in question (the script can be terminated at any time by R-clicking the green H in the
system tray and selecting the “Exit” option from the context menu.
/
Loop, 2 ; 2 occurrences will be processed
{
/
If the specified window exists, bring it into focus (The window is identified by window title, which is “Delete Multiple Items” in this example.
Partial titles are also acceptable.). If the window does not exist, wait until it does exist and then bring it into focus.
*/
WinWait, Delete Multiple Items,
IfWinNotActive, Delete Multiple Items, , WinActivate, Delete Multiple Items,
WinWaitActive, Delete Multiple Items,
/*
once the dialog in question is in focus, we can click the "No" button to close out the dialog in a number of ways. Here's one such way. With the
initial control focus and the tab count required to move the control focus to the "No" button in mind, we can use a simple loop to maneuver the
dialog control focus to the desired button. Once the correct control is in focus, we can act on this control by sending input with a "SendInput"
statement. In your case, this likely means sending an ENTER key stroke to effectively press the dialog's "OK" button.
*/
Loop, 1 ; send 1 TAB key strokes to move the dialog's focus to the desired control
{
SendInput, {TAB}
; Send, {TAB} ; alternatively there's the "Send" statement
}
SendInput, {ENTER} ; "click" the in focus button
}
GuiClose:
^!q::ExitApp ; Assign a hotkey (ctrl + alt + q) to terminate this script
"
Max actually has some internal functionality that operates similarly (to help automate Max UIs that aren’t exposed to MAXScript). Search for “DialogMonitorOPS” in the MAXScript docs if you’re curious. Presumably Maya has similar functionality.
If you decide to try the AHK route, let me know if you run into any snags.