赞
踩
问题:
我没有得到任何语法错误,直到我尝试构建UI时运行脚本。一切似乎都很好,直到我运行最后2行代码。Python for Maya:“对象的名称不唯一。”当从课堂上调用对象来构建用户界面时
我收到以下错误: 错误:RuntimeError:文件行41:对象的名称'mst_txtfld_x_value'不是唯一的。
我行8〜9作出肯定deleteUI,所以我假设文本框正在创建两次。
或者有什么我不了解类应该如何工作? 我是新来的类,并希望解释为什么我得到这个错误。
验证码:
import maya.cmds as mc
from functools import partial
class MoveSelTool(object):
def __init__(self, *args):
pass
if(mc.window("ak_move_sel_tool_window", query=True, exists=True)):
mc.deleteUI("ak_move_sel_tool_window")
def build_window_UI(self):
self.window = mc.window("ak_move_sel_tool_window",
title="Move Selection Tool")
self.columnLayout = mc.columnLayout()
self.txt_directions = mc.text(align="left",
label="Directions: Input translation increment.\n")
self.rowColumn = mc.rowColumnLayout(numberOfColumns=8)
self.txt_x = mc.text(label=" X: ",
align="right")
self.txtfld_x = mc.textField("mst_txtfld_x_value",
ann='input units to move X',
width=50)
self.txt_y = mc.text(label=" Y: ",
align="right")
self.txtfld_y = mc.textField("mst_txtfld_y_value",
ann='input units to move Y',
width=50)
self.txt_z = mc.text(label=" Z: ",
align="right")
self.txtfld_z = mc.textField("mst_txtfld_z_value",
ann='input units to move Z',
width=50)
self.txt_space = mc.text(label=" ")
self.move_btn = mc.button(label="Move")
#ui commands
mc.button(self.move_btn,
edit=True,
command=partial(self.move_selection))
mc.textField("mst_txtfld_x_value",
enterCommand=partial(self.move_selection))
mc.textField("mst_txtfld_y_value",
enterCommand=partial(self.move_selection))
mc.textField("mst_txtfld_z_value",
enterCommand=partial(self.move_selection))
#show ui
mc.showWindow(self.window)
def query_mst_user_input(self):
self.x_value = mc.textField("mst_txtfld_x_value",
query=True,
text=True)
self.y_value = mc.textField("mst_txtfld_y_value",
query=True,
text=True)
self.z_value = mc.textField("mst_txtfld_z_value",
query=True,
text=True)
return (self.x_value, self.y_value, self.z_value)
def move_selection(self):
self.mst_user_selection = mc.ls(selection=True)
self.mst_user_inputs = query_mst_user_input()
mc.move(self.mst_user_selection,
self.mst_user_inputs[0],
self.mst_user_inputs[1],
self.mst_user_inputs[2],
relative=True)
def show(self):
self.build_window_UI()
mst=MoveSelTool()
mst.show()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。