MUserEventMessage

http://download.autodesk.com/us/maya/2009help/index.html


On Thu, Jan 27, 2011 at 8:50 AM, Ofer Koren <[email protected]> wrote:

> I don't think you can register your own events into the maya callback
> system. Maya wouldn't know when to trigger the event, and I don't know of a
> way to do that explicitly (there's no OpenMaya.MMessage.*triggerEvent* method
> for you to call).
>
> Developing a loose callback/dispatch (aka slot/signal) system isn't too
> difficult in python:
>
> CALLBACKS = defaultdict()
>
> def registerCallback(eventName, callback, *args, **kwargs):
>      CALLBACKS[eventName].append((callback, args, kwargs))
>
> def triggerEvent(eventName, **moreKwargs):
>
>      for (callback, args, kwargs) in (CALLBACKS.get(eventName) or []):
>          finalKwargs = kwargs.copy()           # so we don't modify the
> original
>          finalKwargs.update(moreKwargs)
>          try:
>               callback(*args, **kwargs)
>          except:
>               import logging
>               logging.exception("Error in callback %s" % callback)   #
> using 'logging.exception' is better than 'print'
>
>
> I've previously developed a dispatching module on top of python's own *logging
> *module, which already has the [robust] mechanics for doing that at it's
> core. I found that worked pretty well and was easy to extend.
>
> - Ofer
> www.mrbroken.com
>
>
>
> On Wed, Jan 26, 2011 at 11:18 PM, Donal McMullan 
> <[email protected]>wrote:
>
>> I'm working on a Python plugin and I'd like it to be able to emit an event
>> so that other python scripts running in Maya can respond to this event.
>>
>> I guess what I want is to be able to define and then emit a custom
>> OpenMaya.MSceneMessage - say for example kCoffeeReady. My other scripts
>> would be able to do something like:
>>
>> OpenMaya.MSceneMessage.addCallback(OpenMaya.MSceneMessage.kCoffeeReady,
>> self.add_milk)
>>
>> Is that possible? I'm having a hard time grokking the documentation.
>>
>> D
>>
>> --
>>
>> Donal McMullan
>> Production Engineer
>>  Desk: x3310
>>  Direct: +64 4380 3810 <tel:+6443803810>
>>  Mobile: +64 2166 1254 <tel:+6421661254>
>>
>> --
>> http://groups.google.com/group/python_inside_maya
>>
>
>  --
> http://groups.google.com/group/python_inside_maya
>

-- 
http://groups.google.com/group/python_inside_maya

Reply via email to