如何在当前选择的节点之前通过python选择一个节点?
例如,我想在所有“写入”节点之前恰好添加一个“钳位”节点.
解决方法:
该代码段使您可以在现有Write节点的上游定义一个节点.
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
然后调用上游方法(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)