对象名“testUI”不是uniqu

2024-04-26 18:14:46 发布

您现在位置:Python中文网/ 问答频道 /正文

在执行下面的代码时,将在运行代码的第一个实例上创建窗口。如果我尝试编辑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"

Tags: selffalsetrueifdef错误windowprint
1条回答
网友
1楼 · 发布于 2024-04-26 18:14:46

使用dock=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语句未执行。你知道吗

相关问题 更多 >