AREA forums upgrade
Read more about the planned upgrade of our forums
  • 1/3
You are here: Forum Home / Autodesk® Maya® / Python / [solved] Python UI control callbacks?
IMPORTANT ANNOUNCEMENT ABOUT AREA FORUMS
  RSS 2.0 ATOM  

[solved] Python UI control callbacks?
Rate this thread
 
64078
 
Permlink of this thread  
avatar
  • Total Posts: 74
  • Joined: 15 November 2010 10:46 AM

problem:

import maya.cmds as cmds

def exampleWindow
():
    
lWindow cmds.window()
    
cmds.columnLayout()
    
lTextCtrl cmds.textlabel "click-me" )
    
cmds.buttoncommand "exampleFunction( %s )" lTextCtrl )
    
cmds.setParent".." )
    
cmds.showWindowlWindow )

def exampleFunctionlTextCtrl ):
    
cmds.textlTextCtrledit Truelabel "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.textlabel "click-me" )
    
mel.eval( "$tmpTextCtrl = \"%s\"" lTextCtrl )
    cmds
.buttoncommand "exampleFunction( \"$tmpTextCtrl\" )" )
    
cmds.setParent".." )
    
cmds.showWindowlWindow )

def exampleFunctionlVarName ):
    
lTextCtrl mel.eval( "$tmp = %s" lVarName )
    cmds
.textlTextCtrledit Truelabel "full" )
    
exampleWindow()

basically i am using a mel global variable for editing a control via a python callback.



Replies: 1
/img/forum/light/default_avatar.png

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?

Author: seedthomas

Replied: 08 March 2012 04:37 AM  
avatar

I got it working:
import maya.mel as mel
was missing



Replies: 0