PDA

View Full Version : Repeating UI tasks with UIAccessor and DialogMonitorOPS


bloggs
12-15-2007, 07:42 PM
Hi all i'm just trying to get max to cycle through some basic max tasks. in this case i want to just use the freeze transform tool without having to copy some of the code.

i have bee trying to get the DialogMonitorOps to work properly but its seems to not even recognize the code PressButtonByName or even PressDefault.

i thought the process for doing this was to call what dialogue is open and the press the defualt button eg "yes" on freezeTranform and by name is "Yes"

anyway he is a loop. this is not really how i would use this but i want to see if i can get it to work on one button press.

for myhelpers in selection do
(

macros.run "Animation Tools" "FreezeTransform"
--UIAccessor.PressDefaultButton
WindowHandle = DialogMonitorOPS.GetWindowHandle()
UIAccessor.PressButtonByName WindowHandle "Yes"
true

)

anyhelp would be greatly apreciated as there is not alot of help or referance of using these simple operations.

cheers

john

RustyKnight
12-15-2007, 08:46 PM
Hi all i'm just trying to get max to cycle through some basic max tasks. in this case i want to just use the freeze transform tool without having to copy some of the code.

i have bee trying to get the DialogMonitorOps to work properly but its seems to not even recognize the code PressButtonByName or even PressDefault.

i thought the process for doing this was to call what dialogue is open and the press the defualt button eg "yes" on freezeTranform and by name is "Yes"

anyway he is a loop. this is not really how i would use this but i want to see if i can get it to work on one button press.

for myhelpers in selection do
(

macros.run "Animation Tools" "FreezeTransform"
--UIAccessor.PressDefaultButton
WindowHandle = DialogMonitorOPS.GetWindowHandle()
UIAccessor.PressButtonByName WindowHandle "Yes"
true

)

anyhelp would be greatly apreciated as there is not alot of help or referance of using these simple operations.

cheers

johnYou have a number of issues John. The first is, the dialog window is what is called a "blocking" event.

That is, you code will "stop" running UNTIL the dialog is dismissed. So once you call "macros.run "Animation Tools" "FreezeTransform"", nothing else is executed UNTIL AFTER the dialog is dismissed, one way or the other, so you attempt to press the default button is not been executed.

What you need to do is setup a listener/callback, which is notified when a dialog appears and react to it then.

For example...

-- Unregister any previous listeners...keep things tidy
DialogMonitorOPS.unRegisterNotification id:#eyeInTheSky

-- my function for handeling the dialog
fn mf = (
-- Get the window handle of the current dialog
local windowHandle = DialogMonitorOPS.GetWindowHandle()

-- Make sure this is a valid handle...
if (windowHandle != 0) then (

-- Get the title of the window
local title = UIAccessor.GetWindowText WindowHandle

-- Make sure it's the "freeze transforms" dialog
if (title == "Freeze Transforms") then (

-- Dismiss the dialog via it's default value ("yes")
UIAccessor.PressDefaultButton()

)

)

return true
)

-- register the callaback
DialogMonitorOPS.RegisterNotification mf id:#eyeInTheSky
-- enable the monitor
DialogMonitorOPS.Enabled = true

-- Run the script
macros.run "Animation Tools" "FreezeTransform"

-- Clean up
DialogMonitorOPS.unRegisterNotification id:#eyeInTheSky
-- You should only call this if you are not performing any other
-- monitoring processes...
DialogMonitorOPS.Enabled = false


Hope that helps
Shane

bloggs
12-15-2007, 09:21 PM
thanks man a great help it makes perfects scence why its not working now. just one question though. when you all the ID :#eyeInTheSky is that a call function for the DialogMonitorOPS and are there others and if so where do you find them. i'm just trying to understand all the parts of the code and that sorta dosent make scence unless its the fuction that look spacificaly for dialogues in the case the freeze transform.

cheers


john

RustyKnight
12-16-2007, 01:13 AM
thanks man a great help it makes perfects scence why its not working now. just one question though. when you all the ID :#eyeInTheSky is that a call function for the DialogMonitorOPS and are there others and if so where do you find them. i'm just trying to understand all the parts of the code and that sorta dosent make scence unless its the fuction that look spacificaly for dialogues in the case the freeze transform.

cheers


john

The id parameter is an "application context" flag. That is, I can group a number of callbacks under the same id and when I'm ready, un-register all of them simultanously.

This is a design shared with all the callback mechanisms in max.

Imagine you have two callback functions, one dismiss an okay/cancel dialog, the other fills out a form and clicks okay.

With the idea flag, I know I can group the two callbacks together and unregister them in a single call, without effecting the rest of the application or other scripts.

Soooo, the ID parameter can be anything you want, I actually used the value from the example in the docs.

...that should just about confuse the subject nicely ;) ...

Shane

bloggs
12-17-2007, 06:42 PM
hay man thanks for that makes scence now. got it working perfectly. its easy to work out new ways to use this within a script now i have a good example of how it works

thanks again for all the help.

cheers

john

RustyKnight
12-17-2007, 09:37 PM
hay man thanks for that makes scence now. got it working perfectly. its easy to work out new ways to use this within a script now i have a good example of how it works

thanks again for all the help.

cheers

johnPleasure :)

Have to admit, when I first started using it, it took some work to get it to work to.

Shane

CGTalk Moderation
12-17-2007, 09:37 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.