1

这是我的问题:

我想为每个选定的节点创建一个 CheckBox。我已经设法为每个节点创建了具有正确名称的复选框,但问题是在复选框中选择它们并打印结果仅返回选择的第一个节点或布尔结果(真或假),无论如何复选框被选中。我找不到答案。

感谢一切!

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()
4

1 回答 1

2

如果要从面板返回信息,则需要创建自己的 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,面板将返回一个字典,{nodeName:True/False}说明用户是否按下 OK,或者None用户是否取消。

于 2018-03-22T15:18:35.140 回答