Free Function Friday Ep.34 – removeUnusedSolids

May 13th 2016 08:00:49am

Welcome to Free Function Friday episode removeUnusedSolids. This week we build a function that removes those pesky solid items that are not being used in our project. This also goes for nulls too, since nulls are actually SolidSource items as well. Some users are not aware that a null object can only exist in layer form. The main source for that layer is actually a Solid, so when iterating through the project items you have no direct way of knowing what is a Solid or a Null.

There is a lengthy workaround to discover which is which, but it involves searching every single comp and it’s layers to figure out what is actually a null. Something to discuss in another tutorial though. Today’s function will focus only on SolidSource items, and remove the one’s that are not being used in a composition. This is handy to cleanup a project a little without effecting footage that you would otherwise lose if you ran the “Removed Unused Footage” menu command.

Source Code:

removeUnusedSolids();

function removeUnusedSolids(){
	var proj, itemTotal, curItem;
	proj = app.project;
	itemTotal = proj.numItems;
	for(var i=itemTotal; i >= 1; i--){
		curItem = proj.item(i);
		if(curItem instanceof FootageItem){
			if(curItem.mainSource instanceof SolidSource && curItem.usedIn.length == 0){
				curItem.remove();
			}
		}
	}
}
Checkout more:
Free Function Friday Ep.7 – getSelLayBlendMode
After Effects ExtendScript Training: Ep. 13
Cinema4D Attach Splines To Animated Objects
After Effects ExtendScript Training: Ep. 16 part 1
Free Function Friday Ep.41 – fillCompWithShape