Free Function Friday Ep.15 – getAllTextLayers

January 01st 2016 08:00:38am

Welcome to this week’s episode, getAllTextLayers. Today we get back into some familiar territory, with a function that gathers all of the text layer objects in your project. If you watched the collectFontsUsed episode from a few weeks ago, you’ll see some similar code.

This function will get all of the text layer objects within your project. This can be a handy function for gathering a list of all of the text strings in your project, or as a starting point collection to then process the text layers with an effect, or to apply specific Transform settings if you are dealing with lower thirds.

The test code we use will only search the selected items in the project, but can easily be changed to search all comps if you were to modify the retrievePrimaryComps or the collectAllPrecomps function from earlier in the series.

Source Code:

var a = app.project.selection;
alert(getAllTextLayers(a));


function getAllTextLayers(compAry){
	var compAryLength, layerAry, layerAryLength
	compAryLength = compAry.length;
	layerAry = new Array();
	for(var i=0; i < compAryLength; i++){
		layerAryLength = compAry[i].numLayers;
		for(var ii = 1; ii <= layerAryLength; ii++){
			if(compAry[i].layer(ii) instanceof TextLayer){
				layerAry[layerAry.length] = compAry[i].layer(ii);
			}
		}
	}
	if(layerAry.length > 0){
		return layerAry;
	}else{
		return null;
	}
}
Checkout more:
After Effects ExtendScript Training: Ep. 12 Part 2
Houdini Mardini Buzz
X-Particles Custom Branch Generator
Free Function Friday Ep.8 – moveItemToFolder
Free Function Friday Ep.32 – getKeysBasic