Quantcast
Channel: mel wiki
Viewing all articles
Browse latest Browse all 610

API : How can I author a user event?

$
0
0
This post by Kristine Middlemiss breaks it down very nicely:
Transcribed from that post for prosperity:
# 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)

Also see:

Viewing all articles
Browse latest Browse all 610

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>