Free Function Friday Ep.9 – retrievePrimaryComps

November 20th 2015 08:00:02am

Welcome to another episode of Free Function Friday. This week we will create a function that will retrieve only the primary compositions of a project file. A composition can contain a variety of layers, including other compositions, aka precomps. So what I mean by primary, is that these compositions are not precomps.

For example, if you happen to be working on a feature, the individual shot comps themselves could be primary compositions depending on your workflow. If you had the shot comps gathered in a master timeline for reviewing, then they just became precomps. Some uses for this retrievePrimaryComps function could be to track down the main composition timeline(s) in a messy project, perhaps throw them into a master project folder, or to flag those master compositions for rendering.

You will notice that the layout of this function will look very similar to the collectAllPrecomps a function from a few weeks ago. This will be common when running these kinds of processes. They will usually entail similar steps to reach your goal. The ExtendScript object model for After Effects shows you the path to which you can access each area of After Effects.

There is an overview of the object model here in the beginning of the video. Literally it’s a road map to navigating the application via scripting. Much like a road map for a city, you travel in a certain direction to reach your end destination. While a city has multiple access streets to some areas, After Effects may only have one or possibly two in most cases. It’s a very small city. So in the case of collectAllPrecomps and retrievePrimaryComps, we are traveling to the same destination, but we are just simply looking for two different people when we get there.

Source Code:

alert(retrievePrimaryComps());
/*	TESTING ABOVE	*/


function retrievePrimaryComps(){
	try{
		var allItems, allItemsLength, curItem, primaryCompsAry;
		allItems = app.project.items;
		allItemsLength = allItems.length;
		primaryCompsAry = new Array();
		for(var c=1; c<=allItemsLength; c++){
			curItem = allItems[c];
			if(curItem instanceof CompItem){
				if(curItem.usedIn == false){
					primaryCompsAry.push(curItem);
				}
			}
		}
		return primaryCompsAry;
	}catch(err){alert("Error at line # " + err.line.toString() + "\r" + err.toString());}
}
Checkout more:
Houdini Mardini Wind
Houdini Mardini Escape
Free Function Friday Ep.35 – removeKeyframes
Expression Shorts Auto Layer Offset 2D
After Effects ExtendScript Training: Ep. 3