Free Function Friday Ep.7 – getSelLayBlendMode

November 06th 2015 08:00:39am

Welcome to episode six of Free Function Friday. This week we dive into accessing a layer’s blending mode. The blending mode is an option on an After Effects layer that offers a variety of ways to stack your layers to help them literally blend together for better compositing, as well as to help create interesting color effects.

There is a large list of modes to choose from and there can be the need to find all of the layers set to specific mode so you can then change them, or you may be looking for data from your project to make sure an artist is using the proper mode that you or the client has chosen for your project.

For a small project file this can be easy enough to do manually by just looking at the layers, but there can be times in a larger build for say, lower thirds, or a series of animations where it may not be very time efficient to search through the project manually. This is where scripting can be very helpful, and relieve you of the mundane tasks so you can focus on the more important details of a project.

So far the current blending modes available as of After Effects CC 2015 are:

//Blend mode options.
BlendingMode.ADD;
BlendingMode.ALPHA_ADD;
BlendingMode.CLASSIC_COLOR_BURN;
BlendingMode.CLASSIC_COLOR_DODGE;
BlendingMode.CLASSIC_DIFFERENCE;
BlendingMode.COLOR;
BlendingMode.COLOR_BURN;
BlendingMode.COLOR_DODGE;
BlendingMode.DANCING_DISSOLVE;
BlendingMode.DARKEN;
BlendingMode.DARKER_COLOR;
BlendingMode.DIFFERENCE;
BlendingMode.DISSOLVE;
BlendingMode.DIVIDE;
BlendingMode.EXCLUSION;
BlendingMode.HARD_LIGHT;
BlendingMode.HARD_MIX;
BlendingMode.HUE;
BlendingMode.LIGHTEN;
BlendingMode.LIGHTER_COLOR;
BlendingMode.LINEAR_BURN;
BlendingMode.LINEAR_DODGE;
BlendingMode.LINEAR_LIGHT;
BlendingMode.LUMINESCENT_PREMUL;
BlendingMode.LUMINOSITY;
BlendingMode.MULTIPLY;
BlendingMode.NORMAL;
BlendingMode.OVERLAY;
BlendingMode.PIN_LIGHT;
BlendingMode.SATURATION;
BlendingMode.SCREEN;
BlendingMode.SILHOUETE_ALPHA;
BlendingMode.SILHOUETTE_LUMA;
BlendingMode.SOFT_LIGHT;
BlendingMode.STENCIL_ALPHA;
BlendingMode.STENCIL_LUMA;
BlendingMode.SUBTRACT;
BlendingMode.VIVID_LIGHT;

//Example on how to set the value
var myLayer = app.project.item(1).layer(1); //Assumes first project item is a comp and first layer is an AVLayer.

myLayer.blendingMode = BlendingMode.VIVID_LIGHT;

Source Code:

var a = app.project.item(1).selectedLayers;
alert(getSelectedLayersBlendMode(a)[0].layerObj);
/*	TESTING ABOVE	*/


function getSelectedLayersBlendMode(layerObjAry){
	var blendModeNames, blendModeNamesLen, blendModeObjects, blendModeObjectsLen, layerObjAryLen, results;
	layerObjAryLen = layerObjAry.length;
	blendModeObjects = new Array();
	results = new Array();
	blendModeNames = BlendingMode.reflect.properties;
	blendModeNames.pop(1);	/*	Remove __proto__	*/
	blendModeNamesLen = blendModeNames.length;
	for(var b=0; b<blendModeNamesLen; b++){
		blendModeObjects.push("BlendingMode." + blendModeNames[b].toString().toUpperCase());
	}
	blendModeObjectsLen = blendModeObjects.length;
	for(var l=0; l<layerObjAryLen; l++){
		for(var i=0; i<blendModeObjectsLen; i++){
			if(layerObjAry[l].blendingMode == eval(blendModeObjects[i])){
				 results.push({'layerObj': layerObjAry[l], 'layerBlendMode': blendModeNames[i].toString()});
			}
		}
	}
	if(results.length > 0){
		return results;
	}else{
		return null;
	}
}
Checkout more:
Flow Volume 1
X-Particles Fireworks
X-Particles Tangential Advection
After Effects ExtendScript Training: Ep. 16 part 2
Free Function Friday Ep.10 – resizeComp