Q100195: How to customise Nuke scripts exported from Nuke Studio/Hiero



It is not currently possible to change the nodes exported by default from Nuke Studio/Hiero, when exporting a Nuke script using the 'Export..' option or creating the Nuke script via 'Create Comp' or 'Create Comp Special...'.


At export time, the nodes that get added to the Nuke script are created via the hiero.core.nuke.ScriptWriter class. To manually change the default nodes you can override this class and customize the node knobs as required.

Below you can find an example illustrating how to customize the Read node knobs. The script works by:

1) Inheriting the original hiero.core.nuke.ScriptWriter class.

2) Subclassing the addNode() method so that it calls the onNodeAdded() for each node.

3) Defining the onNodeAdded() method. This method defines what changes to apply to which nodes and can be edited to customize the required node settings.

4) Overriding the original ScriptWriter with the edited version.

To use the edited version, you have to save the Python script to .nuke/Python/Startup

If the Python and Startup directories do not already exist in your .nuke directory, then you will need to create them manually. More information about these directories can be found here:
Q100142: How to execute Hiero Python code in Nuke Studio and Hiero on startup

Example showing how to override the ScriptWriter class for a Studio/Hiero export

import hiero.core

OriginalScriptWriter = hiero.core.nuke.ScriptWriter

class CustomScriptWriter(OriginalScriptWriter):

def __init__(self):
def addNode(self, node):
# List of nodes that should actually be added to the script
   nodesToAdd = []
# node might actually be a list of nodes.  If it is, call onNodeAdded for each one
if isinstance(node, hiero.core.nuke.Node):
     nodesToAdd.append( self.onNodeAdded(node) )
for n in node:
         nodesToAdd.append( self.onNodeAdded(n) )
# Call base class to add the node(s)
   OriginalScriptWriter.addNode(self, nodesToAdd)
def onNodeAdded(self, node):
""" Callback when a node is added. Return the node that should actually be added. """
if node.type() == "Read": # Change for the type of node you want to edit
# Make adjustments to all nodes of that type
"on_error", "black") # This sets each Read nodes missing frames to black
"raw", True) # This sets disables the input color transform

return node
hiero.core.nuke.ScriptWriter = CustomScriptWriter

The Python script can be downloaded from the link below.

We're sorry to hear that

Please tell us why