用户界面 - 适用于玛雅的 Python:从类调用对象以生成 UI 时"Object's name is not unique."



问题:

在尝试构建UI之前,运行脚本时不会出现任何语法错误。在我运行完最后两行代码之前,一切似乎都很好。

我得到以下错误:错误:运行时错误:文件行41:对象的名称"mst_xtfld_x_value"不唯一

我确保在第8~9行中deleteUI,所以我假设textField被创建了两次。

或者,我对课程应该如何运作有什么不理解的地方?我刚开始上课,如果能解释一下为什么会出现这个错误,我将不胜感激。

守则:

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()

您忘记了设置ui命令的编辑标志。

#ui commands
mc.button(self.move_btn, 
        edit=True, 
        command=partial(self.move_selection))
mc.textField("mst_txtfld_x_value", edit=True,
            enterCommand=partial(self.move_selection))
mc.textField("mst_txtfld_y_value", edit=True,
            enterCommand=partial(self.move_selection))             
mc.textField("mst_txtfld_z_value", edit=True,
            enterCommand=partial(self.move_selection))

相关内容

  • 没有找到相关文章

最新更新