I was looking through some interesting questions that have come into ADN in the past, and thought I would share this one, it was about the possibility of setting a user event with a scriptJob (Maya Command).
There are no MEL commands to create user events and the scriptJob command cannot be used to wait for them.
However, you can do both in a Python script using API calls.
Here's how you would register a new user event type called 'myEvent':
import maya.OpenMaya as om
om.MUserEventMessage.registerUserEvent('myEvent')
To have a function called 'myFunc' execute whenever the event occurs:
def myFunc(data):
print('Got a myEvent event!')
callbackId =om.MUserEventMessage.addUserEventCallback('myEvent', myFunc)
To send a 'myEvent' event:
om.MUserEventMessage.postUserEvent('myEvent')
To remove the callback function when done:
om.MUserEventMessage.removeCallback(callbackId)
Enjoy
~Kristine
Nice simple breakdown, thanks. I've not used that type of callback yet, but now it's a lot more approachable. Thanks :)
Posted by: Eric Pavey | July 26, 2012 at 01:05 PM