我有一个有灯的数组,每次我创建一个光,它存储的就是我的阵列。我有一个textScrollList,它能显示阵列中所有的灯。
当我加灯时,它不会引用textScrollList。
有人能告诉我如何做到这一点吗,所以每次我做一个灯,它会显示在textScrollList中。或者用刷新按钮。
谢谢!
我现在的代码是:
import maya.cmds as cmds
lights=[]
myWindow = cmds.window(title='My Lights', wh=(200,400),sizeable =False )
cmds.columnLayout()
cmds.showWindow(myWindow)
LightsButton = cmds.button(label='Make Lights', command = "makeLights()", width =200,height = 25,align='center')
def makeLights():
lights.append(cmds.shadingNode('aiAreaLight', asLight=True))
LightSelector = cmds.textScrollList( numberOfRows=8, allowMultiSelection=True,append=(lights), showIndexedItem=4, selectCommand = 'selectInTextList()' )
发布于 2018-05-10 11:24:56
您可以添加一个函数,它将用灯光刷新列表。这可以在您创建一个新的光之后调用,这样它就可以添加到列表中。您还可以添加一个刷新按钮来调用相同的功能,如果您在场景中添加/删除灯光,它将正确更新。
你不需要把灯添加到一个列表中,并跟踪它。相反,您可以使用cmds.ls()
来收集场景中的所有灯光。除非您确实出于某种原因需要列表,否则很容易编辑下面的示例来使用它:
import maya.cmds as cmds
# Clear the listview and display the current lights in the scene.
def refreshList():
# Clear all items in list.
cmds.textScrollList(lightSelector, e=True, removeAll=True)
# Collect all lights in the scene.
allLights = cmds.ls(type='aiAreaLight')
# Add lights to the listview.
for obj in allLights:
cmds.textScrollList(lightSelector, e=True, append=obj)
# Create a new light and add it to the listview.
def makeLights():
lights.append(cmds.shadingNode('aiAreaLight', asLight=True))
refreshList()
def selectInTextList():
# Collect a list of selected items.
# 'or []' converts it to a list when nothing is selected to prevent errors.
selectedItems = cmds.textScrollList(lightSelector, q=True, selectItem=True) or []
# Use a list comprehension to remove all lights that no longer exist in the scene.
newSelection = [obj for obj in selectedItems if cmds.objExists(obj)]
cmds.select(newSelection)
# Create window.
myWindow = cmds.window(title='My Lights', wh=(200,400), sizeable=False)
cmds.columnLayout()
cmds.showWindow(myWindow)
# Create interface items.
addButton = cmds.button(label='Make Lights', command='makeLights()', width=200, height=25, align='center')
lightSelector = cmds.textScrollList(numberOfRows=8, allowMultiSelection=True, append=cmds.ls(type='aiAreaLight'), showIndexedItem=4, selectCommand='selectInTextList()')
refreshButton = cmds.button(label='Refresh list', command='refreshList()', width=200, height=25, align='center')
希望这能有所帮助。
https://stackoverflow.com/questions/50268586
复制相似问题