Update from the Autodesk developer: The typemapping for sleepCallbackPtr was undeliberately omitted from 2010 and previous versions with python bindings. A timer/repeater solution using the threading.Thread python class will work for most cases. All others will have to resort to a C++ plug-in or move to 2011. :-/
On 13 Sep, 12:47, Ryan <[email protected]> wrote: > I am trying to add a timer callback to Maya 2010; but, I do not > understand how to set a sleep callback for it so that the timer > callback does not monopolize the CPU. In the python api, I thought all > you would have to do is > > import sys > import maya.OpenMaya as OpenMaya > import time > > def sleepCallback(): > time.sleep(0.5) > > def timerCallback(elapsedTime, lastTime, clientData): > sys.stdout.write('test\n') > sys.stdout.flush() > > OpenMaya.MTimerMessage.setRegisteringCallableScript() > status = OpenMaya.MTimerMessage.setSleepCallback(sleepCallback) > id = OpenMaya.MTimerMessage.addTimerCallback(0.1, timerCallback, "") > > But, I get the following error > > # Error: TypeError: in method 'MTimerMessage_setSleepCallback', > argument 1 of type 'MTimerMessage::sleepCallbackPtr' # > > This is a problem as I do not see sleepCallbackPtr available in > MTimerMessage. > dir(OpenMaya.MTimerMessage) > # Result: ['__class__', '__delattr__', '__dict__', '__doc__', > '__format__', '__getattribute__', '__hash__', '__init__', > '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', > '__setattr__', '__sizeof__', '__str__', '__subclasshook__', > '__swig_destroy__', '__weakref__', 'addTimerCallback', > 'currentCallbackId', 'nodeCallbacks', 'registeringCallableScript', > 'removeCallback', 'removeCallbacks', 'setRegisteringCallableScript', > 'setSleepCallback', 'sleepCallback', 'thisown'] # > > This is a none issue with the new MTimerMessage::addTimerCallback() > modification in 2011: > > MTimerMessage::addTimerCallback() has been modified such that it no > longer requires that Maya's idle queue run continuously. As such, the > sleepCallback() and setSleepCallback() methods are no longer needed. > They have been deprecated and will be removed in a future version of > Maya. Also, the problem with timer callbacks firing as soon as they > were added has been fixed. The first firing of the callback will now > occur after the specified period has elapsed. If you had previously > worked around the old behaviour > by always skipping the first firing of the callback, you should remove > that workaround. > > But, I need it to run in both 2010 and 2011. What am I not getting > here? > > Thanks, > Ryan -- http://groups.google.com/group/python_inside_maya
