You don't even need an external module to save your ids in memory :)

---

from maya import OpenMaya


# setup
if not globals().get("my_callbacks"):  # this avoid overriding the ids on
re-run
    my_callbacks = dict()

def addCallback(func):
    idx = OpenMaya.MEventMessage.addEventCallback("timeChanged", func)
    my_callbacks[idx] = func
    return idx

def clearCallbacks():
    for idx in my_callbacks.keys():
        OpenMaya.MEventMessage.removeCallback(idx)
    my_callbacks.clear()

# usage
def do_something(*args, **kwargs):
    print "hello"

addCallback(do_something)
addCallback(do_something)
addCallback(do_something)

print my_callbacks  # {id: func}
clearCallbacks()
print my_callbacks  # empty

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPamJi_RT%3DNjaZSi1-s_1WXHdKTQGmJEguP_QpXJ-_knJNfZTQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to