Last active
July 17, 2024 15:46
-
-
Save mb0rt/032ccf0a42f29248b4309e4077d5cc64 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import nuke | |
| def get_useless_nodes(): | |
| all_nodes = nuke.allNodes() | |
| ignore_class_list = ['BackdropNode', 'Write', 'Viewer'] | |
| remove_list = [] | |
| for node in all_nodes: | |
| # bail if node is on the ignore list. | |
| if node.Class() in ignore_class_list: | |
| continue | |
| # is connected or linked to something? | |
| dependent_list = nuke.dependentNodes(nuke.INPUTS | nuke.HIDDEN_INPUTS, node) | |
| if len(dependent_list) == 0: | |
| remove_list.append(node) | |
| continue | |
| # is disabled? | |
| disable_knob = node.knob('disable') | |
| if not disable_knob: | |
| continue | |
| if disable_knob.isAnimated(): | |
| # if has an expression ignore it | |
| if disable_knob.hasExpression(): | |
| continue | |
| # check keyframes, if one is set to be "not" disabled ignore this node | |
| remove = False | |
| knob_animation = disable_knob.animation(0) | |
| for keyframe in knob_animation.keys(): | |
| if keyframe.y <= 0.0: | |
| remove = False | |
| break | |
| elif disable_knob.value(): | |
| remove = True | |
| if remove: | |
| remove_list.append(node) | |
| return remove_list | |
| def delete_useless_nodes(): | |
| while True: | |
| remove_list = get_useless_nodes() | |
| if not remove_list: | |
| break | |
| for node in remove_list: | |
| nuke.delete(node) | |
| # run | |
| delete_useless_nodes() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment