Nuke Python Temp
Revision as of 17:24, 26 May 2023 by Bernie (talk | contribs) (Created page with "===Switch off heavy nodes=== ====Simple==== Will toggle on/off all the nodes in the list <pre> disableList = ['Defocus' , 'VectorBlur', 'iBlur', 'Convolve', 'MagicDefocus.gizmo'] toggle = -1 nodes = nuke.selectedNodes() if not nodes: nodes = nuke.allNodes() for n in nodes: if n.Class() in disableList: if toggle == -1: toggle = 1.0 if n['disable'].getValue() == 0.0 else 0.0 n['disable'].setValue(toggle) </pre> ====More Subtle==== Creat...")
Switch off heavy nodes
Simple
Will toggle on/off all the nodes in the list
disableList = ['Defocus' , 'VectorBlur', 'iBlur', 'Convolve', 'MagicDefocus.gizmo']
toggle = -1
nodes = nuke.selectedNodes()
if not nodes:
nodes = nuke.allNodes()
for n in nodes:
if n.Class() in disableList:
if toggle == -1:
toggle = 1.0 if n['disable'].getValue() == 0.0 else 0.0
n['disable'].setValue(toggle)
More Subtle
Creates a switch control linking either to disable knobs or multiplies a value by the switch node (like the Transform's 'motionblur' knob). Because how the fuck did the Foundry not add that by default ? Right now still WIP because it fucks up when i delete it.TBD
# this will create a global control switch to enable/disable 'slow' nodes
# or 'disable' knobs by multiplying them by the switch value
slownodes = {
'Transform':'motionblur',
'MagicDefocus.gizmo':'disable'
}
nuke.Undo.name("Add Slow Switch")
nuke.Undo.begin()
nodes = []
allSelection = nuke.selectedNodes()
for nodetype, knob in slownodes.items():
nodes = nuke.selectedNodes(nodetype)
if not nodes and not allSelection:
nodes = nuke.allNodes(nodetype)
if nodes:
s = nuke.toNode('SlowNodesSwitch')
if not s:
s = nuke.nodes.Switch(name='SlowNodesSwitch',which='!disable',tile_color=16728063)
s['disable'].setValue(1)
selectedNodes = allSelection
if not allSelection:
selectedNodes = nodes
xPos = [int(n['xpos'].value()) for n in selectedNodes]
yPos = [int(n['ypos'].value()) for n in selectedNodes]
bbox = [[min(xPos),max(xPos)],[min(yPos),max(yPos)]]
s.setXYpos(bbox[0][0]-200,bbox[1][1]) # bottomleft of selected nodes
#s['onDestroy'].setValue(test)
for node in nodes:
print(' '+node.name()+'>')
if knob == 'disable':
node['disable'].setExpression('!parent.SlowNodesSwitch.which')
else:
# multiply knob by 0 to keep value when at 1
curKnob = node[knob]
if not curKnob.hasExpression():
value = curKnob.value()
if value != 0:
curKnob.setExpression( str(value)+' * parent.SlowNodesSwitch.which')
else:
print(' Skipping {}.{}, already at 0'.format(node.name(),knob))
else:
print(' Skipping {}.{}, already has an expression: {}'.format(node.name(),knob,curKnob.toScript()))
del nodes
nuke.Undo.end()
#print('\n'.join([n.name()+' > '+n.Class() for n in nuke.selectedNodes()]))
#todo: nuke.addOnDestroy(call, args=(), kwargs={}, nodeClass='*')[source]
#s['onDestroy'].setValue('''
#print(nuke.thisNode().dependencies())
#''')
#
#nuke.selectedNodes()[0]['onDestroy'].setValue(str(test))