The camera sometimes lies

Aug 11, 2010 by     1 Comment     Posted under: DotNet

Just a snippet posting this time, sharing a small file callback to lock and unlock a camera’s position. If you need to make sure that a camera in a file doesn’t get moved when it is handled by a different artist, this could be useful. Locking a camera is simple, all you need to do is set the transform lock flags on, and (Thanks to Jason Labbe for this suggestion on CGTalk)  lock the FOV of the camera with a script controller.

Added to a file open callback, you can lock all cameras when a file is opened. I have deployed this on the fix team’s computers as a callback, that way nothing gets moved after animation and the subsequent edit. There are a couple of macros to lock and unlock too, should this need to be altered at any time, but the main idea is that it avoids accidental ‘nudging’ of camera positions between file versions which can be easily done.

Unlocked

cams unlocked

Locked!

cams locked

The callback just sits in a file the script startup directory –

callbacks.removeScripts id:#CamLock   
callbacks.addScript #filePostOpen "macros.run "LoneRobot" "LockAllCameras"" id:#CamLock

And the macro is as follows –

macroScript LockAllCameras
category:"LoneRobot"
toolTip:"Lock all Scene Cameras"
buttontext:"Lock Cams"
(
	if cameras.count > 0 then
	(
	For cam in cameras do
		(
		setTransformLockFlags cam #all
		cam.wirecolor = orange
			if classof cam == TargetCamera then
			(
			LockScript = Float_Script()
			cam.fov.controller = lockscript
			)
		)
	-- check that it isn't the target - checking fot the type property is a good enough way as any
	Format "Camera lock applied to % cameras - %n" (for c in cameras where hasProperty c "type" collect c).count maxFileName
	)
)

macroScript UnlockAllCameras
category:"LoneRobot"
toolTip:"Unlock all Scene Cameras"
buttontext:"Unlock Cams"
(
	if cameras.count > 0 then
	(
		For cam in cameras do
		(
		setTransformLockFlags cam #none
		cam.wirecolor = (color 87 120 204)
			if classof cam == TargetCamera then
			(
			UnlockScript = Bezier_Float()
			cam.fov.controller = Unlockscript
			)
		)
	Format "% cameras unlocked - %n" (for c in cameras where hasProperty c "type" collect c).count maxFileName
	)
)

if someone else asks “Why did you choose orange?”, I’m going on a rampage.

404