Nuke Python Temp

From bernie's
Jump to navigation Jump to search

Switch off heavy nodes


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

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 in WIP because i'm not happy about how it still gives you an expression error when you delete the switch node. TBD

# this will create a global control switch to enable/disable 'slow' nodes
# or 'disable' knobs by multiplying them by the switch value 

slownodes = {

#use the following code to get the selected nodes class types if it's not obvious
#print('\n'.join([' > '+n.Class() for n in nuke.selectedNodes()]))"Add Slow Switch")

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)

            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?

        for node in nodes:
            print(' ''>')
            if knob == 'disable':

                #clean things up if we delete this node. not cleanest code ie it still prompts expression errors and 
                #node names can't be changed
                destroyCode = '\nnuke.toNode(\'''\')[\'disable\'].clearAnimated()'
                destroyCode += '\nnuke.toNode(\'''\')[\'disable\'].setValue(0)'

                # 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')
                        destroyCode = '\nnuke.toNode(\'''\')[\''+ knob +'\'].clearAnimated()'
                        destroyCode += '\nnuke.toNode(\'''\')[\''+ knob +'\'].setValue('+str(value)+')'
                        print('  Skipping {}.{}, already at 0'.format(,knob))
                    print('  Skipping {}.{}, already has an expression: {}'.format(,knob,curKnob.toScript()))
    del nodes

#print('\n'.join([' > '+n.Class() for n in nuke.selectedNodes()]))