Free Function Friday Ep.28 – layersAtCurTime

April 01st 2016 08:00:25am

Welcome to the Free Function Friday series. Today’s function I had made not too long ago and used it for a few in-house scripts I had built. One script was for creating layer markers and the other for changing layer label colors. What made this function handy is that it allowed me to perform both of those tasks on only the layers that were at the current timeline marker.

Basically any layer that was active at the current frame that my timeline cursor was parked at was effected. It made highlighting layers in a VFX shot timeline way easier as well as adding quick notes too. I do explain in the video how to perform the label change setup.

Source Code: (updated with an Object to get more data at once)

var c = app.project.activeItem;
var l = layersAtCurTime(c);

if(l != null){ //Verifies content exists
	var temp = new Array();
	var lLen = l.length;
	for(var b=0; b < lLen; b++){
		/*
			Our Object has 4 attributes...
			'obj': Gets the layer Object
			'name': Gets layer name
			'in': Gets layer in point
			'out': Gets layer out point
		*/
		temp.push(l[b].name);	//Get layer name
	}

	alert("Results:\n"+temp.join("\n")); //Alerts a list of layer names
}

/*	TESTING ABOVE	*/


function layersAtCurTime(compObj){
	var curComp, cTime, allLayers, allLayersLen, curLayer, layIn, layOut, activeLayers;
	curComp = compObj;
	cTime = curComp.time;
	if(curComp instanceof CompItem){
		allLayers = curComp.layers;
		allLayersLen = allLayers.length;
		activeLayers = new Array();
		for(var i=1; i<=allLayersLen; i++){
			curLayer = allLayers[i];
			layIn = curLayer.inPoint;
			layOut = curLayer.outPoint;
			if(curLayer.active == true){
				activeLayers.push({'obj': curLayer, 'name': curLayer.name, 'in': curLayer.inPoint, 'out': curLayer.outPoint});
			
			}
		}
		if(activeLayers.length > 0){
			return activeLayers;
		}else{
			return null;
		}
	}else{
		return null;
	}
}
Checkout more:
Houdini | FFX Collection
Houdini | Loops
Expression Shorts Swinging Motion Part 2
Free Function Friday Ep.25 – collectAllSolids
Expression Shorts Attach 2D Layer To 3D Layer