[solved] Python UI control callbacks?

[solved] Python UI control callbacks?

Anonymous
Not applicable
763 Views
2 Replies
Message 1 of 3

[solved] Python UI control callbacks?

Anonymous
Not applicable
problem:


import maya.cmds as cmds

def exampleWindow():
lWindow = cmds.window()
cmds.columnLayout()
lTextCtrl = cmds.text( label = "click-me" )
cmds.button( command = "exampleFunction( %s )" % lTextCtrl )
cmds.setParent( ".." )
cmds.showWindow( lWindow )

def exampleFunction( lTextCtrl ):
cmds.text( lTextCtrl, edit = True, label = "works" )

exampleWindow()

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



workaround:

import maya.cmds as cmds

def exampleWindow():
lWindow = cmds.window()
cmds.columnLayout()
lTextCtrl = cmds.text( label = "click-me" )
mel.eval&#40; "$tmpTextCtrl = \"%s\"" % lTextCtrl &#41;
cmds.button( command = "exampleFunction( \"$tmpTextCtrl\" )" )
cmds.setParent( ".." )
cmds.showWindow( lWindow )

def exampleFunction( lVarName ):
lTextCtrl = mel.eval&#40; "$tmp = %s" % lVarName &#41;
cmds.text( lTextCtrl, edit = True, label = "full" )

exampleWindow()


basically i am using a mel global variable for editing a control via a python callback.
0 Likes
764 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
I was just testing your script ... the mel - line isn´t working for me. I get :
# Error: global name 'mel' is not defined
# Traceback (most recent call last):
# File "<maya console>", line 16, in <module>
# File "<maya console>", line 7, in exampleWindow
# NameError: global name 'mel' is not defined #

did you define mel earlier?
0 Likes
Message 3 of 3

Anonymous
Not applicable
I got it working:
import maya.mel as mel
was missing
0 Likes