You are changing scopes, so your "self" variable is no longer available.
When you call cmds.expression() and python(), the code will be executed in
the global namespace. In order to access your object you'll need to
reference it from the global object name. If you are running this from the
script editor, your object would be named "test". So the quick fix is to
change the expression from self.testFunction to test.testFunction.
Hopefully this has tweaked your spidey senses. Hardcoding an object
instance name into the method will be difficult to maintain, and difficult
to re-use.
Expressions can be multi-line strings. You may be able to find a way to
create your object within the expression and then call that method from
that object.
This example should work from the script editor(untested):
import maya.cmds as cmdsfrom functools import partial
class TestClass(object):
def testFunction(self):
print "testFunction"
myExpression = """myTestObject = TestClass()myTestObject.testFunction()"""
cmds.expression( s = myExpression )
It might help to describe your overall goal. This example is not robust as
it needs the TestClass to be defined in the global scope. If you ever want
to put that class code into a module the expression would no longer be able
to address it.
Best of luck,
Jesse
--
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/CANESWi1gb6YgyYonDSiNkozXCjaYkWctsQROCcF6BWPXfc4Xmg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.