Page 1 of 1

VCS python scripts

Posted: Fri Jan 14, 2011 4:34 am
by duncan
Hello VCS users!

I'm a bit of a python novice but I'm trying to write a script that will cycle through a list of focal lengths on the VCS device.

We've found the thumbstick a little too imprecise and prone to accidental changes when something else is mapped to the other axis.

I can access the camera in python and change the focal length but it is reset as soon as the VCS is made live. Is the VCS (and it's focal length property) accessible in python? If I list all devices in my scene I only get this:

Any ideas?

Re: VCS python scripts

Posted: Fri Jan 14, 2011 3:25 pm
by morgan
Hey Duncan,

Here's a python script from our friends at Halon. This script can be attached to a button action on the controller, so that button presses on the VCS can cycle thru preconfigured focal lengths:

Code: Select all

# InsightVCS Lens Pan Primo Script
# Courtesy Halon Entertainment.
# Description : Based on Panavision Primo Prime Lenses
# when applied to a 35mm Full Aperture Camera

from pyfbsdk import *
print "Begin Lense script"

DeviceName = "OptiTrack Insight VCS"
arrFocalLengths = [30, 50, 80, 150]
index = 0

def FindDevice(pName):
    for lDevice in FBSystem().Scene.Devices:
        if lDevice.Name == pName:
            return lDevice
    return None

lDevice = FindDevice(DeviceName)
if lDevice:
    prop = lDevice.PropertyList.Find("FocalLength")
        value = prop.Data
        if value == 14.5:
          value = 17.5
        elif value == 17.5:
            value = 21
        elif value == 21:
            value = 27
        elif value == 27:
            value = 35
        elif value == 35:
            value = 40
        elif value == 40:
            value = 50
        elif value == 50:
            value = 65
        elif value == 65:
            value = 75
        elif value == 75:
            value = 85
        elif value == 85:
            value = 100
        elif value == 100:
            value = 125
        elif value == 125:
            value = 150
            value = 14.5
        #value = arrFocalLengths[index]
        prop.Data = value
        print "New Focal length %3.2f " %(value)
        index = index+1
        if index > 3:
            index = 0

print "End Lense Script"

Hope this helps!

Re: VCS python scripts

Posted: Fri Jan 14, 2011 4:09 pm
by JustinDenton
Hi Duncan,

We were running into the exact same issues with working soley with the zoom function. It's great when you are going for that docu/eng feel but most of the time in previs we live in a primes world.

I use this script as a template and then make new ones for each show's camera package. The only thing we would like to do in addition to this is write one for going up lenses and one for going down lenses and map them to different buttons. We just haven't had the time to do it.


Re: VCS python scripts

Posted: Mon Jan 17, 2011 9:25 am
by duncan
Thanks guys. This is exactly what I needed.

I'm working on a few other scripts. I'll share them here if I have time to finish them.


Re: VCS python scripts

Posted: Mon Jan 17, 2011 1:05 pm
by morgan
Hey Guys,

Just for grins - here's a Maya version:

Code: Select all

// NextPrimeLense : Changes the active camera focal length to the next prime lense

global proc NatNextPrimeLense()

    string $currentCamera = `lookThru -q`;
    $focalLength = `getAttr ( $currentCamera + ".focalLength" )`;
    print("Previous Focal Length: " + $focalLength + "\n");
    if ($focalLength == 14.5) {
        $focalLength = 17.5;
    } else if ($focalLength == 17.5) {
        $focalLength = 21;
    } else if ($focalLength == 21) {
        $focalLength = 27;
    } else if ($focalLength == 27) {
        $focalLength = 35;
    } else if ($focalLength == 35) {
        $focalLength = 40;
    } else if ($focalLength == 40) {
        $focalLength = 50;
    } else if ($focalLength == 50) {
        $focalLength = 65;
    } else if ($focalLength == 65) {
        $focalLength = 75;
    } else if ($focalLength == 75) {
        $focalLength = 85;
    } else if ($focalLength == 85) {
        $focalLength = 100;
    } else if ($focalLength == 100) {
        $focalLength = 125;
    } else if ($focalLength == 125) {
        $focalLength = 150;
    } else {
       $focalLength = 14.5;    
    setAttr ($currentCamera + ".focalLength") $focalLength;
    print("New Focal Length: " + $focalLength + "\n");    


Re: VCS python scripts

Posted: Tue Jun 28, 2011 7:15 am
by hutch
hi this is mostly a Motionbuilder issue but entirely related to the above script for cycling through Focal Lengths, so I wonder if anyone can help:

we have a camera set up in MoBu as follows:

HD, Fixed Ratio 2.39
35mm Full Aperture Film Format
Horizontal Aperture Mode
1.96 Film Width
2.67 Film Aspect Ratio

only problem is, when it's set to Horizontal Ap Mode, the script's Focal Lengths get multiplied by the Film Aspect Ratio (2.67).. obviously this is not useful, so one workaround is to set Focal Lengths in the script to numbers that are divided by 2.67...

however, Motionbuilder refuses to go lower than a 48 lens with this setup....? (and even then, the 48 lens is an incorrect value).

If the Ap Mode is set to Focal Length, the script works just fine but the image (camera optics) is incorrect (zoomed in)! We know this by comparing the image to that in Maya, where the Ap Mode is Horizontal... as it should be.

We're fudging it right now by setting a 35mm camera with a Film HEIGHT of 0.82 Inches.. it's very close to what we want, and allows the script to work but is not quite as it should be!

any ideas? I hope I explained it clearly!
Thanks all!

Re: VCS python scripts

Posted: Fri Jul 01, 2011 3:13 am
by hutch
in summary, and following more tests:

- in Horizontal Aperture Mode mode the script's lens value is multiplied by the Film Aspect Ratio (2.67)...?

- in Focal Length Aperture Mode (at a compensated Film Height of 0.82) the Focal Length is not keyed on Record? Only the Field of View...?

- only Vertical Aperture Mode (with a compensated Film Height of 0.82) seems to work for us right now, with Focal Length being keyed OK and Lens value correct as per script.

...but it would be nice to be using Horizontal AM since it's the only 'true' representation of our camera requirements...