Ok, if that's going to work for your use case that's terrific.

I notice you are fixing up file reference paths. You may want to look into
kBeforeReferenceCheck<http://download.autodesk.com/us/maya/2009help/API/class_m_scene_message.html#b052d57c5ce92583c2857742c79f175740d98a9bd4ca755a34e3ab147ed8e48d>.
It's a great entry point for handling all reference path manipulation. I've
used this, for instance, to prefix all references with a common
%ENVIRONMENT_VAR%. It's great because you only need to do this in one
place, whether you are handling user input or file loading, this callback
will be triggered.

-Judah



On Thu, Apr 4, 2013 at 9:56 AM, Sune <[email protected]> wrote:

> On Thursday, April 4, 2013 4:19:56 PM UTC+2, Judah wrote:
> > Yes, that's right. You could use a dictionary or an array of tuples, or
> simply a module or member variable, depending on what makes most sense for
> your situation. This way you would be able to look up your callback later.
> Store the return from the callback creation in a manner that allows you to
> associate it with your call.
> >
> >
> > If the callback is used by a particular module or package then I would
> add a module or static class level var that initializes to None. Once your
> Maya startup runs, you store this callback ID on the var. Then you can
> check to see if that var is None later on. If its not None, you know it's
> been initialized.
> >
> >
> >
> > On Thursday, April 4, 2013, Sune  wrote:
> >
> > On Wednesday, April 3, 2013 10:36:19 PM UTC+2, Sune wrote:
> >
> > > I'm adding and removing callbacks with MSceneMessage from a python
> script. I'd like to somehow query if these callbacks exist already, before
> adding them. I searched for the answer, but came up blank.
> >
> > >
> >
> > > I guess I could define these in a python plugin, then I would only
> ever have one instance, but that seems like a workaround.
> >
> > >
> >
> > > Any help would be great!
> >
> > >
> >
> > > Sune
> >
> >
> >
> > I would be likely just be adding these on start up. When adding
> callbacks all I seem to get back is their id and from their ID I would not
> know what they are, unless I keep track of that myself, that's I think is
> what you are suggesting right?
> >
> >
> > Thanks :-)
> >
> >
> >
> > --
> >
> > 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 post to this group, send email to [email protected]
> .
> >
> > For more options, visit https://groups.google.com/groups/opt_out.
>
> Awesome, thank you! Looks like I'm making a class for each callback, that
> has a add() and remove(). I make the class a singleton, this way I don't
> have to check  if it already exists:
>
> # Untested Code!
> userCallbacks = []
>
> class Singleton(type):
>     _instances = {}
>     def __call__(cls, *args, **kwargs):
>         if cls not in cls._instances:
>             cls._instances[cls] = super(Singleton, cls).__call__(*args,
> **kwargs)
>         return cls._instances[cls]
>
> class Save_Cleanup_Callback(Callback):
>     __metaclass__ = Singleton
>     def __init__(self):
>         self.idList = []
>
>     def add_callback(self):
>
> self.idList.append(OpenMaya.MSceneMessage.addCallback(OpenMaya.MSceneMessage.kAfterSave,
> repath.make_file_references_relative, repath.get_last_save("ma")))
>
> self.idList.append(OpenMaya.MSceneMessage.addCallback(OpenMaya.MSceneMessage.kAfterExport,
> repath.make_file_references_relative, repath.get_last_save("ma")))
>         userCallbacks.append(self)
>
>     def remove_callback(self):
>         for _id in self.idList:
>             OpenMaya.MMessage.removeCallback(_id)
>             userCallbacks.remove(self)
>
> Might be overkill, but seemed like the easiest path (especially with
> stealing the singleton code).
>
> --
> 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 post to this group, send email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
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 post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to