gpt4 book ai didi

python - 在窗口中创建动态按钮

转载 作者:太空宇宙 更新时间:2023-11-03 17:27:14 26 4
gpt4 key购买 nike

我正在尝试根据场景中存在的灯光数量在窗口中创建按钮。当我按下创建按钮时,我收到此错误(# RuntimeError:未指定对象名称。#):

Traceback (most recent call last): File "C:\Program Files\Autodesk\Maya2015\Python\lib\site-packages\pymel\internal\factories.py", line 779, in callback res = origCallback( *newargs )

File "", line 31, in lightLst

File "", line 17, in updateList

File "C:\Program Files\Autodesk\Maya2015\Python\lib\site-packages\pymel\internal\factories.py", line 806, in newUiFunc return beforeUiFunc(*args, **kwargs)

File "C:\Program Files\Autodesk\Maya2015\Python\lib\site-packages\pymel\internal\factories.py", line 947, in newFuncWithReturnFunc res = beforeReturnFunc(*args, **kwargs)

File "C:\Program Files\Autodesk\Maya2015\Python\lib\site-packages\pymel\internal\pmcmds.py", line 134, in wrappedCmd res = new_cmd(*new_args, **new_kwargs)

RuntimeError: No object name specified. #

我有点坚持这个问题,我找不到适合我的答案。这是代码:

import maya.cmds as cmds
import maya.mel as mel
import pymel.core as pm

class createWindowClass(object):
def __init__(self, *args):
pass
def show(self):
self.createWindow()

def turnOn(totalLgt, *args):
print "Enter turnOn"

def turnSolo(totalLgt, *args):
print "Enter turnSolo"

def updateList(name, totalLgt, *args):
print "update %s" % name

self.button = pm.button(label="ON", e=True, command = lambda *args: turnOn(totalLgt))
self.button = pm.button(label="SOLO", e=True, command = lambda *args: turnSolo(totalLgt))

def lightLst(*args):
totalLgt = 0

#list all lights in scene
lis = pm.ls(type='light')
print lis
for lgt in lis:
totalLgt += 1
nameLgt = lgt.longName()
name = nameLgt.split("|")[1]
print name
updateList(name, totalLgt)

#CREATE WINDOW
def createWindow(self):
windowID = 'Light Control'
if pm.window(windowID, exists = True):
pm.deleteUI(windowID)

pm.window(windowID, title = "Modify Lights", width = 100, sizeable = True)
pm.rowColumnLayout(numberOfColumns=1, columnWidth=[(10,120)], columnOffset=[10,"right",5])
pm.text(label=" ******** Light list ******** \n")
pm.button(label="CREATE", command = lightLst)
pm.text(label= " \n ***************************** \n ")
window_obj = pm.window(windowID)
window_obj.show()

cls = createWindowClass()
cls.show()

如果有人能给它带来一些启发,我真的很感激!

最佳答案

您必须编写 pm.button(label="CREATE", command = self.lightLst) 并且必须将 self 作为内部方法的第一个参数传递类(class)。

关于python - 在窗口中创建动态按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32396982/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com