/* Auto Camera Rig Script Use this script to set up a rigged camera. Use the "camera controls" effects sliders to control the camera rig. Stu Maschwitz pointed out some deficiencies with the original version of this script and provided a sample project of a much better implementation of a rigged camera project. Unfortunately, there seem to be a couple of show stoppers for recreating his project via scripting and I'd love some feedback if anybody has worked through these issues If not I'll send them off to aebugs@adobe.com. The first is the addCamera() method assumes a point of interest in its constructor. That seems to make the UI equivalent of layer:transform:Auto Orient:Off impossible. I've tried setting the property to Null, etc. with no success. Interestingly, there is a useful assistant to set the property. Secondly, I can't seem to set the slider control range via scripting. I can set the value but not the range so this may be less of a show stopper than the first. I've uploaded the changes that reflect Stu's sample project, so if you find running the script then turning Auto orient off (command-option 0, on the Mac..control-alt 0, windows? I don't have a Windows box handy), and can live with the slider range limitation, then great. Send any fixes my way and I'll incorporate them. I think I see why nobody took this one on . Chris Prosser made the suggestion of launching the "Auto Orient" dialog from the script which is a pretty decent workaround This script was originally requested by Kyle Sims at: http://www.adobeforums.com/cgi-bin/webx?14@@.3bbd48e4 and http://www.aenhancers.com/viewtopic.php?t=317 Altered and updated with suggestions from Stu Maschwitz Copyright 2006 - Dale Bradshaw, dale@creative-workflow-hacks.com http://creative-workflow-hacks.com Free To Distribute, but you must maintain this header if used without alteration, please also include a link to http://creative-workflow-hacks.com if posted on the web If you use parts of this script please include my contact info as attribution (suggested but not required...thanks) v1.0 July 13, 2006 v1.1 July 14, 2006 updated to reflect input from Stu Maschwitz, all of the expressions are based on his sample project v1.2 July 14, 2006 added autoLaunch of "Auto Orient" dialog from suggestion by Chris Prosser v1.3 July 15, 2006 changed "Auto Orient" off to position expression = position + [0,0,100] */ function main(){ var layers = activeItem.layers; var w = activeItem.width /2 ; var h = activeItem.height /2 ; app.beginUndoGroup("Apply Auto Camera Rig"); var cameraControlNull = activeItem.layers.addNull(); cameraControlNull.name = 'Camera Controls'; cameraControlNull.threeDLayer = true; var posX = cameraControlNull("Effects").addProperty("Slider Control"); posX.name = 'X Position'; posX.slider.setValue(w); var posY = cameraControlNull("Effects").addProperty("Slider Control"); posY.name = 'Y Position'; posY.slider.setValue(h); var posZ = cameraControlNull("Effects").addProperty("Slider Control"); posZ.name = 'Z Position'; var pan = cameraControlNull("Effects").addProperty("Slider Control"); pan.name = 'Pan'; var tilt = cameraControlNull("Effects").addProperty("Slider Control"); tilt.name = 'Tilt'; var roll = cameraControlNull("Effects").addProperty("Slider Control"); roll.name = 'Roll'; var focalLength = cameraControlNull("Effects").addProperty("Slider Control"); focalLength.name = 'Focal Length (mm)'; focalLength.slider.setValue(35); var imagePlane = cameraControlNull("Effects").addProperty("Slider Control"); imagePlane.name = 'Image Plane (horizontal inches)'; imagePlane.slider.setValue(.98); var positionExpression = '[effect("X Position")("Slider"), effect("Y Position")("Slider"), effect("Z Position")("Slider")]'; var yRotationExpression = 'effect("Pan")("Slider")'; cameraControlNull.yRotation.expression = yRotationExpression; cameraControlNull.position.expression = positionExpression; cameraControlNull.position.setValue([w,h]); var zoomExpression = 'FocalLength = thisComp.layer("Camera Controls").effect("Focal Length (mm)")("Slider");hFilmPlane = thisComp.layer("Camera Controls").effect("Image Plane (horizontal inches)")("Slider") * 25.4;thisComp.width * (FocalLength/hFilmPlane);'; var xRotationExpression = 'thisComp.layer("Camera Controls").effect("Tilt")("Slider")'; var zRotationExpression = 'thisComp.layer("Camera Controls").effect("Roll")("Slider")'; var cameraPointOfInterestExpression = 'position + [0,0,100]'; var riggedCamera = activeItem.layers.addCamera('Rigged Camera',[w,h]); riggedCamera.position.setValue([w,h]); riggedCamera.orientation.setValue([0,0,0]); riggedCamera.pointOfInterest.expression = cameraPointOfInterestExpression; riggedCamera.zoom.expression = zoomExpression; riggedCamera.xRotation.expression = xRotationExpression; riggedCamera.zRotation.expression = zRotationExpression; riggedCamera.parent = cameraControlNull; //app.settings.getSetting(sectionName, keyName); /*uncomment to use "Auto Orient" off remove alert('"Auto Camera Rig" needs to have Auto-Orient set to "Off", please set it in the following dialog'); app.executeCommand(app.findMenuCommandId("Auto-Orient...")); */ app.endUndoGroup(); } //check that a single active Comp is selected function checkPrerequisites(){ var selectAlert = "Please select a single active Comp."; if ((activeItem != null) && (activeItem instanceof CompItem)){ main(); }else{ alert(selectAlert); } } //globals var items = app.project.items; var activeItem = app.project.activeItem; checkPrerequisites();