Free Function Friday Ep.25 – collectAllSolids

March 11th 2016 08:00:40am

Welcome to episode 25 of the Free Function Friday series. Today we go over how to collect all of the SolidSource objects in your project. One little thing to keep in mind with After Effects though is that Null layers are also technically SolidSource objects as well. So while the Null layer object acts as a null, it’s source is a solid and will read like one in the project panel.

I’ve already gone down the road of trying to differentiate the two and while it can sort of be done, it’s not a fast process. It can also only be performed on Nulls that are actively being used in a comp. If a Null layer has been deleted from a comp and only exists as an asset in the Project Panel, then it is now solely a SolidSource object and it cannot be determined if it was created as a Null initially.Unless the default name still has “Null” in it, but that would not be a long term reliable system since the user can change that name at any point.

For the Nulls still being used in a comp, you will need to loop through every single comp in your entire project and check every single layer to see if that layer object is a null layer using

layerObject.isNull;

Then you grab the source of that layer and proceed to exclude it or include it in another array depending on your needs. I’m not going to go over that today though, as I am trying to keep these videos as short and direct as I can.

Source Code:

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

function collectAllSolids(){
	var proj, itemTotal, curItem, itemAry, code;
	itemAry = new Array();
	proj = app.project;
	itemTotal = proj.numItems;
	for(var i = 1; i <= itemTotal; i++){
		curItem = proj.item(i);
		if(curItem.mainSource instanceof SolidSource){
			itemAry.push(curItem);
		}
	}
	if(itemAry.length > 0){
		return itemAry;
	}else{
		return null;
	}
}
Checkout more:
Free Function Friday Ep.27 – currentTime
Free Function Friday Ep.21 – collectCompCameras
Free Function Friday Ep.8 – moveItemToFolder
Expression Shorts Wiggle Only One Direction
Curves: Volume 1