繁体   English   中英

Python for Maya:从类调用对象以构建UI时,“对象的名称不是唯一的”

[英]Python for Maya: “Object's name is not unique.” when calling object from class to build UI

问题:

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

我收到以下错误: 错误:RuntimeError:文件行41:对象的名称'mst_txtfld_x_value'不是唯一的。

我确保在第8〜9删除了UI ,所以我假设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))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM