Source code for nukescripts.edit

# Copyright (c) 2009 The Foundry Visionmongers Ltd.  All Rights Reserved.

# cut the current node and then paste a copy after every other node.
# This was a throb invention, not sure how useful it is.

import nuke_internal as nuke
import nukescripts

# Edit menu
[docs]def cut_paste_file(): return "%clipboard%"
[docs]def node_copypaste(): nuke.nodeCopy(cut_paste_file()) nodes = nuke.allNodes(); for i in nodes: i.knob("selected").setValue(False) nuke.nodePaste(nukescripts.cut_paste_file())
[docs]def remove_inputs(): for node in nuke.selectedNodes(recursive=True): thisGroup = node.parent() if thisGroup is not nuke.root() and ( thisGroup.locked() or thisGroup.subgraphLocked() ) : lockedReason = "published" if thisGroup.subgraphLocked() else "locked" raise RuntimeError("Can't remove input because " + thisGroup.name() + " is " + lockedReason) for i in nuke.selectedNodes(recursive=True): for j in range(i.inputs()): i.setInput(j, None)
[docs]def extract(): """Disconnect all arrows between selected and unselected nodes, and move selected nodes to the right. This function is maintained only for compatibility. Please use nuke.extractSelected() instead.""" nuke.extractSelected()
[docs]def branch(): selnodes = nuke.selectedNodes(recursive=True) if not selnodes: return; # Use parent group of the first selected node as the context # for branching. This will need to be updated if supporting # branching across multiple groups. thisGroup = selnodes[0].parent() if thisGroup is not nuke.root() and ( thisGroup.locked() or thisGroup.subgraphLocked() ) : lockedReason = "published" if thisGroup.subgraphLocked() else "locked" raise RuntimeError("Can't branch because " + thisGroup.name() + " is " + lockedReason) top_node = None for i in selnodes: totalinputs = i.inputs() for j in range(totalinputs): if i.input(j).knob("selected").value() is False: top_node = i.input(j) if top_node is None: return with thisGroup: nuke.nodeCopy(nukescripts.cut_paste_file()) nuke.nodePaste(nukescripts.cut_paste_file()) firstpastenode = None selnodes = nuke.selectedNodes(recursive=True) for i in selnodes: firstpastenode = i xpos = i.knob("xpos").value() i.knob("xpos").setValue(xpos+80) if firstpastenode is not None: firstpastenode.setInput(0, top_node)