Maya Python issue

Maya Python issue

Anonymous
Not applicable
421 Views
2 Replies
Message 1 of 3

Maya Python issue

Anonymous
Not applicable
i have a class A that creates new renderLayer in maya

when user clicks create button (of class A) , a command is calling a function of the class , say funcA

cmds.button( label="Passes",command=("self.funcA()"))


now, this class A (resides in a file) in a package and is called from another class B

but with the click following error occurs

NameError: file <maya console> line 1: name 'self' is not defined # 


What am i missing

there is another command which works
cmds.button( label=" Close ", command=("cmds.deleteUI(\"" + self.win + "\", window=True)") )


this too has a 'self' being called. But this works
0 Likes
422 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
0 Likes
Message 3 of 3

crydrk
Explorer
Explorer
I don't know if this actually solves the problem, but I usually pass commands a different way.

For example:

import maya.cmds as cmds

class PrintWindow():

def __init__(self):
win = cmds.window()
cmds.columnLayout()
cmds.button(label = 'Print', command = self.printer)
cmds.checkBox(label = 'Checkbox', changeCommand = self.printer)
cmds.showWindow(win)

def printer(self, junk):
print 'We have reached the class method "printer"'
print 'This is what gets passed in when called:', junk

PrintWindow()


Perhaps it could be having a problem finding the method because of calling the function in quotes? Not sure but just a thought. The reason why I add a 'junk' is because when the method is called, a value is passed in. I added the checkbox to show that for things like checkboxes and dropdowns the value is passed but in the case of a button it's always false. I'm not sure if that is also the case when passing a string of the function so just in case I added that tangent of an explanation 🙂
0 Likes