Q100126: How to automate the creation of Ocula scripts using Python

SUMMARY

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

MORE INFORMATION

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 where the function 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 node.
  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
  nuke.root()["setlr"].execute()

  # create the read and set up for the frame range
  reader = nuke.createNode("Read",inpanel=False)
  reader.knob("file").setValue(filename)
  reader.knob("first").setValue(first_frame)
  reader.knob("last").setValue(last_frame)
  
  # 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/stereoFootage.%V.###.ext'
first=1
last=20

# Create the Ocula script
createOculaTree(stereoSequence,first,last)

# save out your script
nuke.scriptSaveAs('/path/to/save/oculaScript.nk', True)

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. 
    Example: "Nuke16.0 -t -i" or "Nuke16.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

 

FURTHER READING

Please see the Nuke Python Developer Guide for more information on how to use Nuke's Python API.
 


Keywords: Ocula, python, O_Solver

    We're sorry to hear that

    Please tell us why