So if I understand you correctly you have a class that defines your
character (lets call this Puppet) and the methods of a character etc. You
have a Character GUI that gets the currently defined Puppet and stores it
internally in the UI for use. What you want to do is NOT recreate
this Puppet object when opening the UI for what ever reason. Probably
speed.
I think you should be looking at a SINGLETON class but I don't like the
idea and try to avoid them.
What I would do.... Sudo code to follow
Stamp some type of UUID on a character object (the physical node in maya,
root node or whatever node you search for in code, your own custom node etc)
You store a module level dict for all your cached MCharacters or in maya
globals via the __main__ import trick (not so clean and open to abuse)
__module__._gPuppets = {}
Scan the maya scene for characters and instantiate those that you need to
based on the UUID
def getPuppets():
# search scene and create instances if needed
# UUID is any unique way of identifying your character. A unique name
might do the job
UUIDS = set()
for character in scene:
UUIDS.add(character.UUID)
if character.UUID not in __module__. _gPuppets .keys():
__module__. _gPuppets [character.UUID] = Puppet(character) #
Make your class only if you need to
# now pop off the invalid UUIDS...
# IE a new file or a character has been deleted, so clear the dict
[__module__._gMChacters.pop(k) for k in set(__module__.
_gPuppets.keys()) - UUIDS]
return __module__._gPuppets
Now you can just import this module and use this function in your UI.
On Thu, Jul 19, 2012 at 5:07 PM, Josh Burton <[email protected]> wrote:
> So this may be a simple thing but I'm been butting my head against it a
> while and was trying to figure out how to do this. So what I have is this:
>
> 1. Character class instance with pertinent data stored
> 2. Gui class instance that instances that character class on load
>
> Up till now, i've just been instancing within the instance so
> guiInstance.CharacterInstance but I seemed silly to reinstance the
> character every time the guiInstance is loaded. So what I wanted was to
> instance the characterInstances to the 'root' of maya to a holder.
> Something like 'CharacterHolderClass.character' and then when the gui
> initializes, it'll look to see if the character has already been instanced
> and if not, will instance it to the root holder then link it within itself.
>
> I can make the instance and some of the functionality via something like
> this:
> #mel.eval('python("cgmPuppet.__dict__[%s] =
> PuppetFactory(%s);")'%("'%s'"%name,"'%s'"%name))
>
> However, that's pretty sloppy to me and I'd love to be able to see the
> base instance of cgmPuppet from within the gui instance but haven't been
> able to find a way to see it. I've tried global as well as some other
> things but I'm hitting my head in the wall.
>
> Any help would be appreciated:)
> -j
>
> --
> view archives: http://groups.google.com/group/python_inside_maya
> change your subscription settings:
> http://groups.google.com/group/python_inside_maya/subscribe
>
--
David Moulder
http://www.google.com/profiles/squish3d
--
view archives: http://groups.google.com/group/python_inside_maya
change your subscription settings:
http://groups.google.com/group/python_inside_maya/subscribe