After selecting a node (or nodes), checks the dependencies upstring in the node tree and removes all unused nodes. v1.3 Loop optimization v1.2. Also working with backdrops
CleanScript
Updated: 1 August 2023
Author: diripirate
Compatible Nuke versions: 11.0 or later
Compatibility: Linux, Windows
Select one or more nodes and it will clean up the script, just saving the nodes used and its dependencies (including expressions)
menu.py
import CleanScript_panel
sMenu = nuke.menu('Nuke').addMenu('Scripts')
sMenu.addCommand('Clean Script', 'CleanScript_panel.main()')