Python 对于 Nuke:Select 当前节点之前

Python for Nuke: Select node before current

如何通过 python 在当前 select 编辑的节点之前 select 一个节点?

例如,我想在所有 "Write" 个节点之前添加一个 "Clamp" 节点。

此代码片段允许您在现有写入节点上游定义一个节点。

import nuke

iNode = nuke.toNode('Write1')

def upstream(iNode, maxDeep=-1, found=None):

    if found is None:
        found = set()
    if maxDeep != 0:
       willFind = set(z for z in iNode.dependencies() if z not in found)
       found.update(willFind)

       for depth in willFind:
           upstream(depth, maxDeep+1, found)

    return found

然后调用方法upstream(iNode).

你之前发给我的脚本片段应该是这样的:

allWrites = nuke.allNodes('Grade')
depNodes = nuke.selectedNode().dependencies()

for depNode in depNodes:
    depNode.setSelected(True) 

queueElem = len(allWrites)
trigger = -1

for i in range(1,queueElem+1):
    trigger += 1

    for write in allWrites[(0+trigger):(1+trigger)]: 
        write.setSelected(True)
        nuke.createNode("Clamp")

        for all in nuke.allNodes():
            all.setSelected(False)