Create a ticket
Follow

Q100195: How to customise Nuke script exports from NukeStudio/Hiero

SUMMARY

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

 

MORE INFORMATION

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. Information about finding your .nuke directory can be found here: Q100048: Nuke Directory Locations

If the Python and Startup directories do not already exist in your .nuke directory, then you will need to create them manually.

 

"""
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):
   OriginalScriptWriter.__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) )
   
else:
     
try:
       
for n in node:
         nodesToAdd.append( self.onNodeAdded(n) )
     
except:
       
pass
       
   
# 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
     node.setKnob(
"on_error", "black") # This sets each Read nodes missing frames to black
     node.setKnob(
"auto_alpha", True) # This sets each Read nodes missing frames to black

   
return node
     
         
hiero.core.nuke.ScriptWriter = CustomScriptWriter

  

The Python script can be downloaded from the link below.

Was this article helpful?

We're sorry to hear that

Please tell us why
6 out of 6 found this helpful

Comments