Shotcams v6

So here we go with the latest script then. A rewrite and expansion of my listcameras script. Wrote this for our thesis project in school (wich will be up soon). I had 6 shotcams to tangle with witch turned into a very tedious process when you have to go into Panels > Perspective > YourCamera every time you want to change camera. Not to mention that we also had a shot associated with each camera with a specific time range witch just made it a nightmare to handle manually.

What the script does is that it lists all your cameras in the scene (not the perspective one tough) and provides controls for specifying a timerange for each, the ability to lock the cams, allows you to look through them with a single click plus allows for continuous playback of all cameras so that you essentially have your shot in full in your viewport. Also added a function for creating a bat file to render out all cameras in batchmode.

Shotcams v6

The colorful explanation for the scriptwindow is as follows:
Black – camera names
Red – lock or unlock camera
Yellow – Look through camera
Green – Start and endrange for each camera
Pink – Plays all cameras in sequence
Range button – Switches to your perspective cam and sets the timerange from first to last camera so it spans your entire sequence

Download here or select and copy the code below. Gimme a shout if you want additional features etc,

"""
 shotCams_v6.py
 ------------------
 Author:
	Jonne

 Date:
	18 feb 2010

 Www:
	http://www.jonne.net

 Mail:
	jonne@jonne.net

 Description:
	PYTHON script. Lists cameras in the scene and provides
	an easy interface for switching between them and for maintaining
	continious play, managing shots,locking cameras etc

"""
import maya.cmds as mc

def setupCams():
	"""
	create custom attributes on cameras
	containing start and end frame
	"""

	# Loop cameras in the scene and add attributes for start and endframe
	for i in getCameras():

		checkStart = mc.attributeQuery('startFrame', n=i,exists=1)
		checkEnd = mc.attributeQuery('endFrame', n=i,exists=1)
		if checkStart == 0 and checkEnd == 0:
			mc.addAttr(i, longName='startFrame', attributeType='long', hidden=1, defaultValue=1)
			mc.addAttr(i, longName='endFrame', attributeType='long', hidden=1, defaultValue=20)

def setCamAttr(camName):
	"""
	Called to set the start- and endframe of a camera
	"""

	# fix to get around mayas handling of buttons etc
	def b(*args):
		startFrame = mc.textField('startfield'+camName, q=1,text=1)
		endFrame = mc.textField('endfield'+camName, q=1,text=1)
		mc.setAttr(camName + '.startFrame', int(startFrame))
		mc.setAttr(camName + '.endFrame', int(endFrame))
	return b

def getCamAttr(camName,attrName):
	""" Get a camera attribute """

	value = mc.getAttr(camName + '.' + attrName)
	return value

def getCameras():
	""" List the cameras in the scene """

	cams = mc.listCameras(p=1)
	newCamlist = []

	for i in cams:

		if i <> 'persp' and i <> 'shakeCam':
			newCamlist.append(i)

	return newCamlist

def lookThruCam(value):
	""" Look through the selected cam """

	def b(*args):
		mc.lookThru('perspView', value)
		startFrame = getCamAttr(value,'startFrame')
		endFrame = getCamAttr(value,'endFrame')
		setCurrenttimerange(startFrame, endFrame)
		mc.select(value)

	return b

def checkExpression():
	""" Check if the expression named framePrinter excists """

	expressionList = mc.ls(et='expression')
	state = 0
	for i in expressionList:
		if i == 'framePrinter':
			state= 1

	return state

def createExpression(*args):
	"""
	Create the expression. Expression executes the python def checkTime
	If expression excists delete it
	"""

	if checkExpression() == 0:
		expString = "//Check to see if camera needs to change\r\npython(\"checkTime()\");"
		mc.expression(n='framePrinter', s=expString)
	else:
		mc.delete('framePrinter')

def checkTime():
	""" Playback all cameras in sequence """

	camlist = getCameras()
	for i in range(len(camlist)):

		try:
			nextStartFrame = getCamAttr(camlist[i+1],'startFrame')
			startFrame = getCamAttr(camlist[i+1],'startFrame')
			endFrame = getCamAttr(camlist[i+1],'endFrame')

		except IndexError:
			nextStartFrame = ''

		# switch camera and set timerange
		if mc.currentTime(q=1)+1 == nextStartFrame:
			mc.lookThru(camlist[i+1])
			setCurrenttimerange(startFrame, endFrame)

def checkBoxOn(value):
	""" Lock all keyable attributes of a camera """

	def b(*args):

		camAttributes = mc.listAttr(value, v=1,k=1)
		for i in camAttributes:
			mc.setAttr(value + '.' + i, lock=1)

	return b

def checkBoxOff(value):
	""" Unlock camera """

	def b(*args):
		camAttributes = mc.listAttr(value, v=1,k=1)
		for i in camAttributes:
			mc.setAttr(value + '.' + i, lock=0)

	return b

def checkState(value):
	""" Check to see if camera is locked or not """

	def b(*args):
		try:
			return mc.getAttr(value + '.translateX', lock=1)
		except:
			return 0

	returnValue = b()
	return returnValue

def setCurrenttimerange(startRange, endRange):
	""" Sets the current timeranged based on the selected camera """

	mc.playbackOptions( minTime=startRange)
	mc.playbackOptions( maxTime=endRange)
	mc.currentTime(startRange, e=1)

def getRange(*args):
	""" Get the range for the whole scene """

	camList = getCameras()
	startRange = getCamAttr(camList[0],'startFrame')
	endRange = getCamAttr(camList[len(camList)-1],'endFrame')

	# set current range to match whole scene
	setCurrenttimerange(startRange,endRange)
	mc.lookThru('perspView', 'persp')

def createWindow():
	""" Create the window """

	windowName = 'Shotcams v6 - jonne.net'

	# check for excisting window
	if (mc.window(windowName, exists=True)):
		mc.deleteUI(windowName , window=True)

	mc.window( windowName, title=windowName, widthHeight=(250, 250) )
	mc.rowColumnLayout(numberOfColumns=5, columnWidth=[(1, 80), (2, 20), (3, 40), (4, 40), (5, 40)])

	# list cameras with start- and endframes
	for i in getCameras():

		startFrame = mc.getAttr(i+'.startFrame')
		endFrame = mc.getAttr(i+'.endFrame')
		mc.text(i)
		mc.checkBox( label='', onc=checkBoxOn(i), ofc=checkBoxOff(i), value=checkState(i) )
		mc.button( label='select', command=lookThruCam(i), width=20 )
		mc.textField('startfield' +i, tx=startFrame,ec=setCamAttr(i),aie=1,rfc=setCamAttr(i))
		mc.textField('endfield' +i, tx=endFrame,ec=setCamAttr(i),aie=1,rfc=setCamAttr(i))

	mc.text('Play all cams')
	mc.checkBox( label='', onc=createExpression, ofc=createExpression, value=checkExpression() )
	mc.text(' ')
	mc.text(' ')

	mc.text(' ')
	mc.button(label='Refresh', command=initWindow, bgc=[1,1,1])
	mc.text(' ')
	mc.button(label='Range', command=getRange, bgc=[1,1,1])
	mc.text(' ')
	mc.button(label='.bat', command=createBatWindow, bgc=[1,1,1])

	mc.showWindow()

def batFile():
	""" Create content for batwindow """

	line = ""
	for i in getCameras():
		startFrame = str(getCamAttr(i,'startFrame'))
		endFrame = str(getCamAttr(i,'endFrame'))
		filename = mc.file(q=1, sn=1)

		line += 'render -r mr -cam ' + i + ' -s '+startFrame+' -e '+endFrame+' ' + filename + '\n'

	return line

def createBatWindow(*args):
	""" Create window for bat-file output """

	windowName = 'batWin'
	if (mc.window(windowName, exists=True)):
		mc.deleteUI(windowName , window=True)

	mc.window( windowName, title=windowName, widthHeight=(300, 200) )
	mc.paneLayout()
	mc.scrollField(text=batFile())

	mc.showWindow()

def initWindow(*args):
	"""	Initialize window """

	setupCams()
	createWindow()

## init script
initWindow()
I wish to do something Great and Wonderful, but I must start by doing the little things like they were Great and Wonderful”
~ Albert Einstein