对象名称“ testUI”不是唯一的

时间:2019-01-10 19:44:30

标签: python oop user-interface maya

在下面执行此代码时,将在运行代码的第一个实例上创建窗口。如果我尝试编辑方法createCustomUI,则会出现问题。

我收到以下错误

错误:第1行:对象的名称“ testUI”不是唯一的。

...。并且未创建窗口。我正在尝试弄清为什么会发生此错误,并为此找到了一个好的解决方案。

import pymel.core as pm

from functools import partial


class ControlCurveTools_UI(object):

    def __init__(self):
        self.windowName = "testUI"
        self.windowHeight = 1000
        self.windowWidth = 250

        self.createUI(self.windowName, self.windowHeight, self.windowWidth, True, False)

    def createUI(self, windowName, windowHeight, windowWidth, dock, scroll):

        if dock == True:

            if pm.dockControl(windowName + "_dock", exists = True):
                pm.deleteUI(windowName + "_dock")
        else:

            if pm.window(windowName, exists = True):
                pm.deleteUI(windowName)

        print "here"
        print self.windowName

        self.window = pm.window(windowName, title = windowName, w = windowWidth, h = windowHeight, mnb = False, mxb = False)

        print "here2"
        self.mainlayout = pm.columnLayout(adj = True)

        # Uniqe UI stuff
        self.createCustomUI()

        print "here3"       


        if dock == True:
            pm.dockControl(windowName + "_dock", label = windowName + "_dock", area = "left", content  = self.window, w = self.windowWidth)

        else:   
            pm.showWindow(self.window)


    def createCustomUI(self):

        pm.rowColumnLayout(nc = 1, parent = self.mainlayout, w = self.windowWidth, e=1)

        pm.button(label = "Replace Curve With Selected", p=self.mainlayout)
        pm.button(label = "Mirror Selected Curve", p=self.mainlayout)

        # print "creatingCustomUI"

1 个答案:

答案 0 :(得分:2)

您使用ock = True调用构建方法,因此本节:

    if dock == True:
        if pm.dockControl(windowName + "_dock", exists = True):
            pm.deleteUI(windowName + "_dock")
    else:
        if pm.window(windowName, exists = True):
            pm.deleteUI(windowName)

不删除窗口,因为未执行else语句。