Python (pymxs.runtime) DialogueMonitorOPS not behaving properly

Python (pymxs.runtime) DialogueMonitorOPS not behaving properly

Huston94
Enthusiast Enthusiast
3,365 Views
7 Replies
Message 1 of 8

Python (pymxs.runtime) DialogueMonitorOPS not behaving properly

Huston94
Enthusiast
Enthusiast

I am trying to utilize the DialogueMonitorOPS and UIAccessor in a python script to be able to handle dialogue windows. While testing the example in the documentation with the MaxScript version everything worked perfectly. When I went to convert it all over to Python using the pymxs.runtime module, it doesn't do the same thing. It appears to have worked at first (no errors) but after running it, NONE of the menus work and none of the dialogues will pop up. Here is my converted code:

 

 

from pymxs import runtime as rt


rt.DialogMonitorOPS.unRegisterNotification(ID="#eyeInTheSky")

def handleDialogues():
	win_handle = rt.DialogMonitorOPS.GetWindowHandle()

	print "Dialog Window Handle: {0} - (#{1})\n".format(win_handle, type(win_handle))
	print "Dialog Name: {0} - (#{1})\n".format(rt.UIAccessor.GetWindowText(win_handle), type(rt.UIAccessor.GetWindowText(win_handle)))
	print "Window Class Name: {0} - (#{1})\n".format(rt.UIAccessor.GetWindowClassName(win_handle), type(rt.UIAccessor.GetWindowClassName(win_handle)))
	print "Window Resource ID: {0} - (#{1})\n".format(rt.UIAccessor.GetWindowResourceID(win_handle), type(rt.UIAccessor.GetWindowResourceID(win_handle)))
	print "Is Window: {0} - (#{1})\n".format(rt.UIAccessor.isWindow(win_handle), type(rt.UIAccessor.isWindow(win_handle)))
	print "Window DLL Filename: {0} - (#{1})\n".format(rt.UIAccessor.GetWindowDllFileName(win_handle), type(rt.UIAccessor.GetWindowDllFileName(win_handle)))
	print "Window DLL Description: {0} - (#{1})\n".format(rt.UIAccessor.GetWindowDllDescription(win_handle), type(rt.UIAccessor.GetWindowDllDescription(win_handle)))
	rt.UIAccessor.SetWindowText(win_handle, " All Your Windows Are Belong To Us")
	print "=====================\n"

rt.DialogMonitorOPS.RegisterNotification(handleDialogues, ID="#eyeInTheSky")
rt.DialogMonitorOPS.Enabled = True
rt.DialogMonitorOPS.ShowNotification()

 

Honestly, I am a little unsure of how this even works so any thorough explanations as to what I did wrong would be greatly appreciated. My guess is the ID="#eyeInTheSky" argument isn't working like it's supposed to. Any help would be great. Thanks.

0 Likes
3,366 Views
7 Replies
Replies (7)
Message 2 of 8

Swordslayer
Advisor
Advisor
0 Likes
Message 3 of 8

Huston94
Enthusiast
Enthusiast

No I hadn't at first. I didn't know about that. But I just tried it and it didn't seem to work either. It didn't crash though. Not sure what else to try.

0 Likes
Message 4 of 8

drew_avis
Autodesk
Autodesk

This looks like it might be a bug in the Python / MAXScript pymxs interop.  Just this line disables all my menus:

 

rt.DialogMonitorOps.Enabled = True

 

I'm going to report this as a defect and see if I can get someone to look at it.

 

Drew



Drew Avis
Content Experience Designer
Message 5 of 8

Huston94
Enthusiast
Enthusiast

Gotcha. Thanks a bunch. I was questioning myself lol.

 

As a side note...Is there any online resource that has a thorough explanation on how to use the DialogueMonitoOPS and UIAccessor? Mainly the unRegisterNotification and the RegisterNotification commands. I read the documentation but it is a little vague. I also utilized some old forum posts for MaxScript use but they don't really explain, they just show the solution. I would love to have a full understanding on this so I am confident in using it. Thanks.

0 Likes
Message 6 of 8

drew_avis
Autodesk
Autodesk

I'm not aware of any additional resources, but I always find doing a google search often turns up useful threads in forums or Stack Overflow.  I'm making a note to beef up the explanation of these items in the docs.

 

Drew



Drew Avis
Content Experience Designer
Message 7 of 8

drew_avis
Autodesk
Autodesk

I want to follow up on this issue in case someone else trips over it.

The issue is basically that you need to register a callback before you set DialogMonitorOPS = True.  When you set this, if there is no callback to handle dialog events (including windows, dialogs and menus), the dialog is closed.  You can check whether there is a callback registered by looking at DialogMonitorOPS.RegisterNotification.

 

In this script, you do pass the name of a python function to use as a callback, but this will fail because MAXScript can't "see" the python function.  You need to pass in the name of a MAXScript function.  The other issue is that you need to use

ID=rt.name('eyeInTheSky')

 

Regarding the callback registration issue, here is one possible work around.  It leverages the ability of MAXScript to import Python modules and use them as if they were MAXScript.

# callback_test.py
import pymxs import sys, os rt = pymxs.runtime # add our path so we can import ourselves as a module: sys.path.append(os.path.dirname(os.path.abspath(__file__))) def myCallback(): print "Callback fired!" # import ourselves rt.Execute ('pycallback = Python.Import "callback_test"') # register ourselves as a callback rt.callbacks.addScript(rt.Name('nodeCreated'), 'pycallback.myCallback()')

Hope this helps,

Drew

 



Drew Avis
Content Experience Designer
0 Likes
Message 8 of 8

mannsBYFGQ
Community Visitor
Community Visitor

Hi,

 

So I am a little confused after reading through this. I am also attempting to handle dialog windows using Python, and after testing with the callbacks.addscript method I was unable to get anything working.

 

What would be the best way to handle dialogs in Max using Python?

 

Thanks

0 Likes