Free Function Friday Ep.23 – getCurComp

February 26th 2016 08:00:22am

Welcome to Free Function Friday episode on getting the current composition. The function this week is very simple and short. It just condenses a few lines into a single function for convenience.

When trying to check for the currently open comp in a project it can be simply called by typing

app.project.activeItem;

This would return the actively selected item in the project or the currently open composition depending on which panel is active. We will be adding an if statement to check and make sure it returns only CompItems, or null so we can verify the results. This will prevent any other item in the project, like a FolderItem or FootageItem from being returned by mistake.

Source Code:

function getCurComp(){
	var curComp = app.project.activeItem;
	if(curComp instanceof CompItem){
		return curComp;
	}else{
		return null;
	}
}
Checkout more:
Expression Shorts Auto Layer Offset 2D
Relative Paths with X-Particles Caches
Free Function Friday Ep.15 – getAllTextLayers
Free Function Friday Ep.39 – setMaskPaths
After Effects ExtendScript Training: Ep. 15 part 1