gpt4 book ai didi

python - 为 Nuke 中列表中的每个项目创建一个复选框

转载 作者:行者123 更新时间:2023-12-01 02:03:41 28 4
gpt4 key购买 nike

这是我的问题:

我想为每个选定的节点创建一个复选框。我已经设法为每个节点创建具有正确名称的复选框,但问题是在复选框中选择它们并打印结果的位置仅返回选定的第一个节点或 bool 结果(True 或 False),无论什么复选框被选中。我找不到答案。

谢谢你所做的一切!

import nuke

nodeNames = [n.name() for n in nuke.allNodes('Write')]

names = []
for s in nuke.allNodes('Write'):
n = s['name'].value()
names.append(n)
#print names
#len(names)

writeNodes = ( ", ".join( str(e) for e in names ) )


p = nuke.Panel ('TEST')

for items in names:
de = p.addBooleanCheckBox(items,'True')

p.show()

最佳答案

如果您想从面板返回信息,您需要创建自己的 PythonPanel 子类。像这样的事情:

class WritesPanel( nukescripts.PythonPanel ):
def __init__( self , nodeNames):
nukescripts.PythonPanel.__init__( self, "Write Nodes", "unique.panel.id" )

self.nodeNames=nodeNames

for nodeName in nodeNames:
self.k = nuke.Boolean_Knob(nodeName, nodeName)

self.addKnob( self.k )

# The next function shows the dialog as a modal dialog. Doing this
# automatically adds the 'OK' and 'Cancel' buttons to the dialog.

def showModalDialog( self ):
result = nukescripts.PythonPanel.showModalDialog( self )
if result:
results={}
for nodeName in self.nodeNames:
results[nodeName]=self.knobs()[nodeName].value()
return results
else:
return None

# The following function calls WritesPanel

def launchWritesPanel(nodeNames):
return WritesPanel(nodeNames).showModalDialog()

使用您的nodeNames列表调用launchWritesPanel,如果用户按OK或None,面板将返回{nodeName:True/False}字典 如果用户取消。

关于python - 为 Nuke 中列表中的每个项目创建一个复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49287828/

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