我想知道如何查询输入到文本字段组中的选择,以便对其进行处理。我已经创建了一个窗口,只翻译我在文本字段中加载的对象。错误在于未定义cont
import maya.cmds as cmds
import maya.mel as ml
def set_selected_name (text_field):
cont = cmds.ls (selection = True)
text_field = cmds.textFieldButtonGrp (text_field, edit = True,
text = ''.join (cont),
buttonLabel = '<<<<',
backgroundColor = [0.5098039215686274,
0.5098039215686274,
0.5098039215686274])
return text_field
def translate_x(cont):
cmds.setAttr( cont[0] + '.translateX', 10)
def translate_y():
cmds.setAttr( cont[0] + '.translateY', 10)
def translate_z(*Args):
cmds.setAttr( cont[0] + '.translateZ', 10)
if cmds.window ('window1', q = 1, ex = 1):
cmds.deleteUI ('window1')
cmds.window ('window1',
title = 'Translate Attr',
sizeable = 0,
resizeToFitChildren = True,
menuBar = 1)
cmds.rowLayout (numberOfColumns = 3)
cmds.separator (style = 'double',
height = 6)
cmds.rowLayout (parent = 'window1',
numberOfColumns = 4)
ddd = cmds.textFieldButtonGrp (editable = False,
text = 'Obj',
backgroundColor = [0.029495689326314183,
0.5488975356679637,
0.5488975356679637],
buttonLabel = '<<<<')
cmds.textFieldButtonGrp (ddd, edit = True,
buttonCommand = 'set_selected_name (ddd)')
cmds.separator (style = 'double',
height = 6)
cmds.rowLayout (parent = 'window1',
numberOfColumns = 6)
cmds.separator (style = 'double',
height = 6)
cmds.button (command = 'translate_y()',
backgroundColor = [1.0,
0.7300068665598535,
0.7300068665598535],
label = 'Translate Y')
cmds.separator (style = 'double',
height = 6)
cmds.button (command = 'translate_x(cont)',
backgroundColor = [1.0,
0.9733272297245746,
0.7333333333333333],
label = 'Translate X')
cmds.separator (style = 'double',
height = 6)
cmds.button (command = 'translate_z()',
backgroundColor = [0.7333333333333333,
1.0,
0.7600061036087586],
label = 'Translate Z')
cmds.columnLayout (parent = 'window1')
cmds.separator (style = 'double',
height = 3)
cmds.showWindow ('window1')
# ~ BABLAAM ~
创建您喜欢的任何对象,加载到文本字段中,然后尝试使用按钮进行翻译
我已经按照您的建议调整了代码以添加类,但仍然存在相同的问题。通过在按钮命令中不使用引号,我在尝试运行脚本时会出现此错误,而不是在按下按钮时出现此错误
错误:名称错误:文件第28行:未定义名称“translate_x”
你能不能写一个可行的版本,或者在internet上放置一个链接,显示使用类的方法和使用按钮调用方法?在我的网络搜索中,我没有发现这样的东西,我只是在猜测这些东西应该去哪里
您的代码中有几个问题
set_selected_name()
中使用,是一个局部变量,这意味着函数完成后它将被删除李>使用全局变量可以解决
cont
问题,但不应该这样,因为全局变量是万恶之源。更优雅的方法是将UI封装在一个python类中,并使用实例变量来获得选择相关问题 更多 >
编程相关推荐