Last active
February 11, 2020 10:33
-
-
Save paulwinex/8e561fe3d0fb14ea729a0b9a42fe09bb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import nuke | |
def get_nodes_by_type(node, types): | |
array = [] | |
for inp in range(node.inputs()): | |
inp_node = node.input(inp) | |
if inp_node.Class() in types: | |
array.append(inp_node) | |
array.extend(get_nodes_by_type(inp_node, types)) | |
return array | |
last = nuke.selectedNode() | |
upstream = get_nodes_by_type(last, ['ColorCorrect','Grade']) | |
if not upstream: | |
raise | |
first = upstream[-1] | |
print 'First node:', first.name() | |
# connect unptimult to first | |
unprim = nuke.nodes.Unpremult(inputs=[first.input(0)]) | |
first.setInput(0, unprim) | |
# connect primult to last | |
downstream = last.dependent() | |
prim = nuke.nodes.Premult(inputs=[last]) | |
if downstream: | |
for d in downstream: | |
d.setInput(d.inputs()-1, prim) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment