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:
Expression Shorts Auto Layer Offset 3D
X-Particles Blood
Free Function Friday Ep.30 – addCompMarker
Free Function Friday Ep.3 – runMenuCmd
Expression Shorts Loop