Q100126:如何使用 Python 自动创建 Ocula 脚本

概括

本文介绍了如何使用 Python 和 O_Solver 节点自动创建Ocula脚本。

更多信息

您可以使用Nuke的 Python API 自动创建简单的Ocula脚本,从而节省准备工作的时间。以下示例代码展示了一种实现方法。
以下函数执行以下操作:
  1. 设置Nuke脚本具有两个视图
  2. 为给定的素材创建一个读取节点
  3. 创建一个 O_Solver 节点并将其连接到 Read 节点
  4. 在 O_Solver 节点上为读取序列的第一帧、最后一帧和中间帧创建关键帧。
# 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]))
然后,你可以将此用于一个简单的脚本中,该脚本指向你的素材,运行该函数,然后保存脚本。
# 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/ ocula Script.nk', True)
请注意:要通过 Python 执行 O_Solver 节点,您需要同时使用NukeOcula的交互式许可证。
  • 如果您正在运行Nuke终端会话,则需要在参数中使用“-i”启动它,例如“Nuke16.0 -t -i”或“Nuke16.0 -ti”。

  • 如果您在外部 Python 会话中将Nuke作为 Python 模块使用,则需要在执行“import nuke ”命令之前设置“os.environ["NUKE_INTERACTIVE"] = "1"”。
延伸阅读
有关如何使用Nuke的 Python API 的更多信息,请参阅Nuke Python 开发人员指南

关键词: Ocula 、Python、O_Solver

    我们很遗憾听到

    请告诉我们