Free Function Friday Ep.21 – collectCompCameras

February 12th 2016 08:00:22am

Welcome to the Free Function Friday series, collectCompCameras episode. This week we build a function that will gather the camera layer objects from an array of comp objects that you supply it. This is helpful if needing to adjust any camera layers in your project, or gather data about your camera layers. Since this function accepts an array of comp objects, you can supply it the currently open comp or all of the comps in your project.

From that selection the function will read through every layer in those comps and collect only the layers that are camera layers. In our case we will return a new object that contains the layer index number, the layer name, and the layer object itself. This will give us more options after the fact if we need to do any other processes to these camera layers. As always you can certainly customize the returned value to your needs though.

Source Code:

var s = new Array(app.project.item(1), app.project.item(2)); //Assumes the first and second project items are compositions
var c = collectCompCameras(s);
for(var i = 0; i < c.length; i++){
	alert(c[i].name);
}
/*	TESTING ABOVE	*/

function collectCompCameras(compAry){
	var compAryLen, curComp, layerCount, camCollection, curLayer;
	compAryLen = compAry.length;
	camCollection = new Array();
	for(var i=0; i < compAryLen; i++){
		curComp = compAry[i];
		if(curComp instanceof CompItem){
			layerCount = curComp.numLayers;
			for(var l=1; l<=layerCount; l++){
				curLayer = curComp.layer(l);
				if(curLayer instanceof CameraLayer){
					camCollection.push({'idx': curLayer.index, 'name': curLayer.name, 'obj': curLayer});
				}
			}
		}
	}
	if(camCollection.length > 0){
		return camCollection;
	}else{
		return null;
	}
}
Checkout more:
Ikea Lack Photogrammetry Turntable Part 3
Houdini Vex Point Manipulation
After Effects ExtendScript Training: Ep. 18 Part 3
X-Particles Blood
After Effects Menu Command ID’s