Notifications
Clear all

[Closed] Question about using PressButtonByName

Hey there, sorry for all the questions. I’ve been meaning to post them for a while and now they are just stacking up :\

I have a script where I am using the UI Accessor command PressButtonByName

 UIAccessor.PressButtonByName WindowHandle "OK"

to force automation on some processes that were not, on their own, fully automatable.

But everytime I run that script, I have to shut down Max afterwards because it will force close any window that has an “Ok” button. Is there something I can do in my script to deactivate the button pressing after the script has run?

I am not very familiar with the UIAccessor so this is probably something very simple that I am missing.

Thanks

Tania

8 Replies

Tania,

I assume you are using DialogMonitorOPS.GetWindowHandle() to get the Window handle?
Once you have the handle, you can actually check the name of the dialog you are processing using UIAccessor.GetWindowText WindowHandle or something along those lines. You could apply matchPattern() to the text returned by the method to find a portion of the text that matches the window you want to close.
Once you find the window with the text you want to affect, you could just unregister the monitoring or disable it via DialogMonitorOPS.Enabled = false if you want. But adding a condition based on the text of the dialog to affect only what has to be affected should do it.

Hi Bobo,

Thanks for your response. I’m actually using a chunk of code that I believe you had shown us to begin with. Here it is:

 
fn ANoon_EnvelopeCallbackFunction =
(
WindowHandle = DialogMonitorOPS.GetWindowHandle()
theDialogName = UIAccessor.GetWindowText WindowHandle
if theDialogName != undefined and matchpattern theDialogName pattern:"*Load Envelopes*" do
UIAccessor.PressButtonByName WindowHandle "Match by Name"
UIAccessor.PressButtonByName WindowHandle "OK"
)
DialogMonitorOPS.RegisterNotification ANoon_EnvelopeCallbackFunction ID:#ANoon_Envelopes
DialogMonitorOPS.Enabled = true


However, after I run this script it will close down any window I open with the options of “OK.” Am I doing something wrong?

1 Reply
(@bobo)
Joined: 11 months ago

Posts: 0

I recognize the style, but if I wrote this, I should have said

if theDialogName != undefined and matchpattern theDialogName pattern:“Load Envelopes” do
(
UIAccessor.PressButtonByName WindowHandle “Match by Name”
UIAccessor.PressButtonByName WindowHandle “OK”
)

As it is now, it checks the dialog name against loading envelopes, but then presses the OK regardless of the IF statement. Placing parentheses around makes the whole block (both lines) dependent on the test and should fix the problem you are seeing!

Doh, thanks Bobo.

You did write the code, but I added an extra line thus causing the if loop issue.

What an ridiculous mistake, I am embarasssed!

Thank you for your help!

Tania

Hi Bobo,

Now that I am at work and able to test out the code, I am still finding problems.

The code block now reads :

 
fn ANoon_EnvelopeCallbackFunction =
(
WindowHandle = DialogMonitorOPS.GetWindowHandle()
theDialogName = UIAccessor.GetWindowText WindowHandle
if theDialogName != undefined and matchpattern theDialogName pattern:"*Load Envelopes*" do 
(
UIAccessor.PressButtonByName WindowHandle "Match by Name"
UIAccessor.PressButtonByName WindowHandle "OK"
)

)
DialogMonitorOPS.RegisterNotification ANoon_EnvelopeCallbackFunction ID:#ANoon_Envelopes
DialogMonitorOPS.Enabled = true

throws the error

>> MAXScript DialogMonitor Exception: – Unable to convert: undefined to type: Boolean <<

Try

 
 fn ANoon_EnvelopeCallbackFunction =
 (
 WindowHandle = DialogMonitorOPS.GetWindowHandle()
 theDialogName = UIAccessor.GetWindowText WindowHandle
 if theDialogName != undefined and matchpattern theDialogName pattern:"*Load Envelopes*" then
 (
 UIAccessor.PressButtonByName WindowHandle "Match by Name"
 UIAccessor.PressButtonByName WindowHandle "OK"
 true
 )
 else
 false
 
 )
 DialogMonitorOPS.RegisterNotification ANoon_EnvelopeCallbackFunction ID:#ANoon_Envelopes
 DialogMonitorOPS.Enabled = true
 

The callback function is supposed to return a boolean value. (I should document this better, the example shows it, but it is not spelt explicitly in the docs, my bad).
Since UIAccessor.PressButtonByName() returns a boolean value itself, it wasn’t necessary in your initial version – the result of the function would have been the result of the UIAccessor.PressButtonByName() call that pressed “OK”. But if the IF … DO evaluated to false, it returned ‘undefined’ and DialogMonitorOPS.RegisterNotification() was complaining that it was not receiving a boolean back from the callback function…

See if it works now.

Ahh thanks Bobo. I think during my editing I lost my “true” and that started a landslide of issues. The explanation helped me out alot, I understand what I am looking at alot better now.

my hero :bowdown:

Still had some funky window stuff going on occasionally, so I threw this in there at the end of the script as a failsafe.

 DialogMonitorOPS.Enabled = false

thanks for all your help!