﻿ Jonne.net » Blog Archive » Cycle through cams

Cycle through cams

Time to do some updates. Mel script this time.
Here’s a script for switching cameras. If you have multiple cameras and want to have a keyboardshortcut to switch between them this works.
Put the code below in the command section for the keyboard shortcut.
When ever executing this script (via shortcut or shelfbutton) it will go forward one camera in your list. If you want to have it going the other way ie. backwards change the line with “int $direction = 1;” to “int $direction = 0;” (minus the quotes ofc).
So just paste the script once with the setting on 1 and then do a new shelfbutton or shortcut and paste it again with the setting of 0.

05 feb 2010
Jan-Erik "Jonne" Östman (jonne@jonne.net)


Cycle through cameras with hotkey or shelfbutton. Change
$direction from 1 to 0 if you want to go to the previous
camera instead of the next one.

//**** Change for different direction! ****
int $direction = 1; 	// 1-next camera, 0-previous camera

// init variables
string $cams[] = `listCameras -p`;	// add all cams to and array
string $curCam = `lookThru -q`;		// get the current camera
string $curView = `getPanel -wf `;	// get the active panel
string $nextCam;					// what camera to switch to

for($i = 0; $i < size($cams); $i++)
	// Go forward in camlist
	if ($direction == 1) {
		if ($cams[$i] == $curCam) {

			//error management for checking the array
			if ($i+1 == size($cams)) {
				$nextCam = $cams[0];
			} else {
				$nextCam = $cams[$i+1];

	// Go backward in camlist
	} else {


			//error management for checking the array
			if ($i-1 < 0) {
				$nextCam = $cams[size($cams)-1];
			} else {
				$nextCam = $cams[$i-1];

// Set the selected camera as current
lookThru $curView $nextCam;
~ Albert Einstein