Category Archives: Python

Some Nuke snippets

Extract with mask

extract

def extract_with_mask():
	node = nuke.selectedNode()
	maskNode = nuke.selectedNode().input(node.optionalInput())
	nodeChild = nuke.selectedNode().dependent()
	nodeParent = nuke.selectedNode().input(0)
	
	#deconnexion
	#input
	cpt = 0
	while cpt <= node.minInputs():
		node.setInput(cpt, None)
		cpt = cpt + 1
	#output
	for n in nodeChild:
		if n.Class() in ["Merge2", "DeepRecolor", "Shuffle", "Dissolve"]:
			if n.input(0) == node:
				n.setInput(0, nodeParent)
			else:
				n.setInput(1, nodeParent)
		else:
			n.setInput(0, nodeParent)
	
	#mask connexion
	node.setInput(node.optionalInput(), maskNode)
	
	#positions
	node['xpos'].setValue(node.xpos()+15)
	node['ypos'].setValue(node.ypos()+15)
nuke.menu("Nuke").addCommand("Custom/Extract node with mask", "extract_with_mask()", "ctrl+shift+e")
extract_with_mask()

Continue reading