February 19th 2016 08:00:57am
Welcome to Free Function Friday episode about getting light types. Today we create a function that will get the type of light that is being used in a light layer. One bit of warning, this attribute access was added to light layers starting with After Effects CS5.5 Scripting Changes, so this particular function will not work in any After Effects version earlier than CS5.5. When calling the lightType attribute, you would normally get an enumerated value. If you have been following the Free Function Friday series, you’ll remember that we’ve dealt with enumerated values before when we accessed After Effects languages. With that in mind we dive back into that world and try to make things more understandable for light types.
Source Code:
var l = getLightType(app.project.item(1).layer(1)); //Assumes first item is composition and layer 1 is a Light Layer
if(l != null){
alert(l.name);
}else{
alert(l);
}
/* TESTING ABOVE */
function getLightType(lightObj){
if(lightObj instanceof LightLayer){
switch(lightObj.lightType){
case LightType.PARALLEL:
return {'type':"Parallel", 'name':lightObj.name, 'index':lightObj.index};
break;
case LightType.SPOT:
return {'type':"Spot", 'name':lightObj.name, 'index':lightObj.index};
break;
case LightType.POINT:
return {'type':"Point", 'name':lightObj.name, 'index':lightObj.index};
break;
case LightType.AMBIENT:
return {'type':"Ambient", 'name':lightObj.name, 'index':lightObj.index};
break;
}
}else{
return null;
}
}