View Full Version : Clone Overscan Camera - single-shot Generic script for Layout 11.5+

04-14-2014, 08:29 PM

In the past I've manually set up "overscan" cameras by cloning the camera and adjusting the height/width and field of view of the clone. I spoke with Deuce, and he thought it might be useful to automate this technique with a script.

I'm posting it here in case it's of use as an example script and/or production script. Select a camera in the scene, run this script, and choose an overscan width. It will clone the camera and adjust the field of view of the cloned camera. The original camera is left untouched.

Clone Overscan Camera by Jennifer Hachigian
With thanks to Deuce Bennett.

Usage: select a camera in the scene and run this script to clone an
overscan version of that camera.

import lwsdk

def error(arg1, arg2):
""" simplified way to call an error message. """
lwsdk.LWMessageFuncs().error(arg1, arg2)

def getZoomFactorEnvelope(item):
""" returns the ZoomFactor envelope if it exists, and
None if no ZoomFactor enveloper exists. """
zEnv = None
cGrp = lwsdk.LWItemInfo().chanGroup(item)
chan = lwsdk.LWChannelInfo().nextChannel(cGrp, None)
while chan:
chanName = lwsdk.LWChannelInfo().channelName(chan)
if chanName == "ZoomFactor":
zEnv = chan
chan = lwsdk.LWChannelInfo().nextChannel(cGrp, chan)
return zEnv

def overscanZoomFactorEnvelope(chan, overscan):
""" applies overscan to every key in the ZoomFactor envelope. """
env = lwsdk.LWChannelInfo().channelEnvelope(chan)
key = lwsdk.LWEnvelopeFuncs().nextKey(env, None)
while key:
val = lwsdk.LWEnvelopeFuncs().keyGet(env, key, lwsdk.LWKEY_VALUE)
old_zoom = val[1]
new_zoom = val[1]/(overscan)
lwsdk.LWEnvelopeFuncs().keySet(env, key, lwsdk.LWKEY_VALUE, new_zoom)
key = lwsdk.LWEnvelopeFuncs().nextKey(env, key)

def cloneOverscanCamera():
""" clones a selected camera, adjusts its resolution/zoom,
and renames it with the percentage of overscan involved. """
items = lwsdk.LWInterfaceInfo().selected_items()
if not items:
error("No selected items.", "Please select an item.")

item = items[0]
if lwsdk.LWItemInfo().type(item) != lwsdk.LWI_CAMERA:
error("No selected camera.", "Please select a camera.")

zEnv = getZoomFactorEnvelope(item)

curTime = lwsdk.LWInterfaceInfo().curTime
name = lwsdk.LWItemInfo().name(item)
w, h = lwsdk.LWCameraInfo().resolution(item)

""" get overscan value from user """
text = lwsdk.LWMessageFuncs().askName("Input new width.", "Width", str(w))
overscan = float(text)/float(w)
except ValueError:
error("Wrong value.", "Enter a number next time!")
except TypeError:
error("Cancelled.", "User cancelled operation.")

new_w = int( text )
new_h = int( h * (overscan) )

lwsdk.command("Clone 1")
lwsdk.command("Rename %s_overscan_%d%%" % (name, (overscan-1.0) * 100))
lwsdk.command("FrameSize %d %d" % (new_w, new_h))

if zEnv:
""" apply overscan to the ZoomFactor envelope """
overscanZoomFactorEnvelope(zEnv, overscan)
""" apply overscan to the static ZoomFactor value """
zoom = lwsdk.LWCameraInfo().zoomFactor(item, curTime)
new_z = zoom/(overscan)
lwsdk.command("ZoomFactor %f" % new_z)


04-14-2014, 10:51 PM