swapOutNode v1.1


 
This location is for Registered Users Only.
Perhaps you need to login or register.
Contributor: Nathan Rusch
Function that mostly duplicates Nuke's Ctrl + Shift + drag-and-drop replace-node functionality.
Requirements:
5.2, 6.0, 6.1, 6.2, 6.3 or later
05 Feb 2012
213

Swap Out Node

This function was written per a request to mimic Nuke's native Ctrl + Shift + drag-and-drop node-replacement trick. It duplicates pretty closely, with one notable key difference (that I've noticed so far, anyway):

If you replace a node with multiple primary inputs (say, a Merge) with a single-primary-input node (say, a Grade), the node that was connected to the secondary pipe of the Merge (the A pipe by default) will now be connected to the "mask" input of the Grade node. This differs from the native functionality in that normally only primary inputs are taken into consideration, and node connection stops short of mask inputs.

I've been thinking of ways to get around this issue (.optionalInput() isn't a reliable solution unfortunately), but unless you're doing something really crazy, it shouldn't be a big deal.

It's pretty bare-bones so far, but if you have any ideas or run into any issues, let me know and I'll modify it.

Update 1.1: Added getConnectedNodes function to simply return lists of a node's inputs and outputs.
Please login in order to download these files.

Comments   

 
+1 # lol muly 2012-02-01 13:55
Had to modify the script to suit my needs, needed the targetNode to reconnect where the newNode had been. In the original script it only reconnects the newNode.

def swapOutNode(tar getNode, newNode):
if not isinstance(targ etNode, nuke.Node) or not isinstance(newN ode, nuke.Node):
return False
sourcePos = (newNode.xpos() , newNode.ypos())
targetPos = (targetNode.xpo s(), targetNode.ypos ())
oldSel = []
if nuke.selectedNo des():
oldSel = [node for node in nuke.selectedNo des()]
nukescripts.cle ar_selection_re cursive()
inputNodes = []
outputNodes = []
inputNodes1 = []
outputNodes1 = []
for i in range(targetNod e.inputs()):
inputNodes.appe nd((i, targetNode.inpu t(i)))
for depNode in nuke.dependentN odes(nuke.INPUT S | nuke.HIDDEN_INP UTS, targetNode):
for i in range(depNode.i nputs()):
if depNode.input(i ) == targetNode:
outputNodes.app end((i, depNode))
depNode.setInpu t(i, None)
for ii in range(newNode.i nputs()):
inputNodes1.app end((ii, newNode.input(i i)))
for depNode in nuke.dependentN odes(nuke.INPUT S | nuke.HIDDEN_INP UTS, newNode):
for ii in range(depNode.i nputs()):
if depNode.input(i i) == newNode:
outputNodes1.ap pend((ii, depNode))
depNode.setInpu t(ii, None)
targetNode.setS elected(True)
newNode.setSele cted(True)
nuke.extractSel ected()
targetNode.setS elected(False)
newNode['xpos'] .setValue(targe tPos[0])
newNode['ypos'] .setValue(targe tPos[1])
targetNode['xpo s'].setValue(so urcePos[0])
targetNode['ypo s'].setValue(so urcePos[1])
for inNode in inputNodes:
newNode.setInpu t(inNode[0], inNode[1])
for outNode in outputNodes:
outNode[1].setI nput(outNode[0] , newNode)

for inNode in inputNodes1:
targetNode.setI nput(inNode[0], inNode[1])
for outNode in outputNodes1:
outNode[1].setI nput(outNode[0] , targetNode)
for node in oldSel:
node.setSelecte d(True)
return True
 
 
0 # Jason Nguyen 2012-09-14 18:25
and how do you add the menu for this? put this in my zzz menu but doesn't work
import swapOutNode
zzz.addCommand('swapOutNode', 'swapOutNode.swapOutNode()')

thanks
 
 
0 # Nathan Rusch 2012-09-17 17:31
It's not something that's meant to be used from a menu, but rather a function that could be useful for someone else writing DAG manipulation scripts. If you need a shortcut, Nuke already has one built in (that this tries to duplicate): Ctrl + Shift + drop one node on another.
 

You have no rights to post comments

We have 3270 guests and 70 members online