Last active
August 22, 2023 21:04
-
-
Save UnaiM/323dd8e74f30fc511faf572e1ea59752 to your computer and use it in GitHub Desktop.
Gaffer: trying to add the ability to modify the graph on dispatch
This file contains 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 os | |
import Gaffer | |
import GafferDispatch | |
# Add an 'onDispatch' task input to all task nodes. | |
tasknode_init_orig = GafferDispatch.TaskNode.__init__ | |
def tasknode_init(self, *args, **kwargs): | |
result = tasknode_init_orig(self, *args, **kwargs) | |
if 'onDispatch' not in self: | |
plug = GafferDispatch.TaskNode.TaskPlug('onDispatch', flags=Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic) | |
self.addChild(plug) | |
Gaffer.Metadata.registerValue(plug, 'description', 'Task to execute before the graph is "locked" by the dispatcher.') | |
Gaffer.Metadata.registerValue(plug, 'nodule:type', 'GafferUI::StandardNodule') | |
Gaffer.Metadata.registerValue(plug, 'noduleLayout:section', 'left') | |
Gaffer.Metadata.registerValue(plug, 'plugValueWidget:type', '') | |
return result | |
GafferDispatch.TaskNode.__init__ = tasknode_init | |
# Check for anything connected to 'onDispatch' on the dispatched nodes. | |
def dispatch_signal(dispatcher, nodes): | |
sub_nodes = [] | |
for node in nodes: | |
plug = node['onDispatch'].getInput() | |
if plug: | |
sub_nodes.append(plug.node()) | |
if sub_nodes: | |
name = 'onDispatch_' + dispatcher.getName() | |
sub_dispatcher = GafferDispatch.LocalDispatcher(name) | |
sub_dispatcher['jobsDirectory'].setValue(os.path.join(dispatcher.jobDirectory(), os.path.pardir, os.path.pardir, name)) | |
sub_dispatcher.dispatch(sub_nodes) | |
GafferDispatch.Dispatcher.dispatchSignal().connect(dispatch_signal, scoped=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment