Q100126: How to automate the creation of OCULA scripts using python



This article explains how you can automate the creation of Ocula scripts with an O_Solver node using python.


You can use Nuke's python API to automate the creation of simple Ocula scripts to save you time when preparing work.  The example code below shows one way that you can do this.
The function below does the following:
  1. Sets the Nuke script to have two views
  2. Creates a Read node for given footage
  3. Creates an O_Solver node and connects it to the Read
  4. Creates keyframes on the O_Solver node for the first, last and middle frames of the Read sequence.
# Create an O_Solver keyed at first_frame, last_frame and the mid frame

def createOculaTree(filename, first_frame, last_frame):
  mid_frame = int( (first_frame + last_frame)/2 )

  # set up views

  # create the read and set up for the frame range
  reader = nuke.createNode("Read",inpanel=False)
  # set up the O_Solver node and create a key
  solver = nuke.createNode('O_Solver4_0',inpanel=False)
  solver.setInput(0, reader)
  nuke.execute(solver, nuke.FrameRanges([first_frame, mid_frame, last_frame]))
You can then use this in a simple script that points to your footage, runs the function and then saves the script.
# define the location of your footage
# and the frame range stereoSequence='/path/to/stereoFootge.%V.###.ext'

# Create the Ocula script

# save out your script
nuke.scriptSaveAs('/path/to/save/oculaScript.nk', True)
PLEASE NOTE:  In order to execute the O_Solver node via python you need to be using interactive licenses for both Nuke and Ocula.
  • If you're running a Nuke terminal session then you'll need to launch it with "-i" in your arguments, e.g. "Nuke10.0 -t -i" or "Nuke10.0 -ti"

  • If you are using Nuke as a python module in an external python session then you need to set os.environ[ "NUKE_INTERACTIVE" ] = "1" before your "import nuke" command
Please see the Nuke Python Developer Guide for more information on how to use Nuke's python API.

Keywords: Ocula, python, O_Solver
Was this article helpful?
1 out of 1 found this helpful