3

如何在当前选择的节点之前通过 python 选择一个节点?

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

4

1 回答 1

3

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

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)

在此处输入图像描述

于 2017-06-20T18:15:30.330 回答