This is a lifesaver of a hook. If a broken node completely freezes your script, Nuke won’t even finish loading it unless you disconnect the viewers first. This leaves you completely blind, unable to debug what’s causing the crash or fix the issue.
Drop this code into your main menu.py inside the .nuke folder:
def disconnectAllViewers():
for node in nuke.allNodes('Viewer'):
for i in range(node.inputs()):
node.setInput(i, None)
nuke.addOnScriptLoad(disconnectAllViewers)This function plugs directly into the addOnScriptLoad() callback. When triggered, it loops through every input of every Viewer node in the script and cuts the connection.