Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save aescripts/258020cc91926a914149993b0ccbc492 to your computer and use it in GitHub Desktop.
Save aescripts/258020cc91926a914149993b0ccbc492 to your computer and use it in GitHub Desktop.
#AfterEffects #Script #KBar #MotionScript #Camera
if (app.project.activeItem instanceof CompItem) {
var myCam;
if (app.project.activeItem.activeCamera instanceof CameraLayer)
myCam = app.project.activeItem.activeCamera;
else
myCam = app.project.activeItem.layers.addCamera("Target Camera", [app.project.activeItem.width/2,app.project.activeItem.height/2]);
var myNull = app.project.activeItem.layers.addNull();
myNull.name = "Target";
myCam.cameraOption.focusDistance.expression = "target = thisComp.layer(\"Target\");\nv1 = target.toWorld(target.anchorPoint) - toWorld([0,0,0]);\nv2 = toWorldVec([0,0,1]);\ndot(v1,v2);";
} else {
alert("Please select a comp");
}
@aescripts
Copy link
Author

Added the "3D layer" to NULL(Target), that it would be possible to animate DOF in the plane Z.

if (app.project.activeItem instanceof CompItem) {
var myCam;
if (app.project.activeItem.activeCamera instanceof CameraLayer) 
myCam = app.project.activeItem.activeCamera;
else 
myCam = app.project.activeItem.layers.addCamera("Target Camera", [app.project.activeItem.width/2,app.project.activeItem.height/2]);
var myNull = app.project.activeItem.layers.addNull();
myNull.name = "Target";
myNull.threeDLayer = true;
myCam.cameraOption.focusDistance.expression = "target = thisComp.layer(\"Target\");\nv1 = target.toWorld(target.anchorPoint) - toWorld([0,0,0]);\nv2 = toWorldVec([0,0,1]);\ndot(v1,v2);";
} else {
alert("Please select a comp");
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment