Friday, April 18, 2008

Weird Maya Python plug-in behavior

I found a weird Maya Python plug-in behavior yesterday.

When I make a plug-in like this,


class ClassD(object):
pass

def initializePlugin(mobject):
print ClassD.__module__

def uninitializePlugin(mobject):
pass

and load it, it prints out

__builtin__

How come a method is defined in the built in module?
It means you cannot use global declaration.
You need to either import the plug-in module inside the code like,

import pyCommandPort
pyCommandPort.someattribute = somevalue

or need to separate the code from the plug-in file and import it.

The globals() returns the right dictionary, and the class is not
in the builtin module. Looks Maya is doing some complicated things.

No comments: