我正在尝试根据场景中存在的灯光数量在窗口中创建按钮。当我按下创建按钮时,我收到此错误(#RuntimeError: No object name specified.#):
回溯(最近一次调用最后):文件“C:\Program Files\Autodesk\Maya2015\Python\lib\site-packages\pymel\internal\factories.py”,第 779 行,回调 res = origCallback( *newargs )
文件“”,第 31 行,在 lightLst 中
文件“”,第 17 行,在 updateList 中
文件“C:\Program Files\Autodesk\Maya2015\Python\lib\site-packages\pymel\internal\factories.py”,第 806 行,在 newUiFunc 中返回 beforeUiFunc(*args, **kwargs)
文件“C:\Program Files\Autodesk\Maya2015\Python\lib\site-packages\pymel\internal\factories.py”,第 947 行,在 newFuncWithReturnFunc res = beforeReturnFunc(*args, **kwargs) 中
文件“C:\Program Files\Autodesk\Maya2015\Python\lib\site-packages\pymel\internal\pmcmds.py”,第 134 行,在 WrappedCmd res = new_cmd(*new_args, **new_kwargs)
RuntimeError: 未指定对象名称。#
我有点坚持,我找不到适合我的答案。这是代码:
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()
如果有人能给它一些启示,我真的很感激它!