-
Bypass layer as Null object
Hello all,
I’m making a script that can detect a layer and it’s properties, then spit the location back out ; so that I may add some interpolation to it. Excuse the hacky way that I go about it. It mainly gets the job done until it has to iterate through the layers within a for loop. Within the for loop it’s saying layer is null. I use a method “eval” to try and run the interpolation. I placed an If statement to try and catch the null layer. It does it’s job, but now the function dosen’t work because the if statement ignores all layers. Would love some aid on this – thanks :
ar comp = app.project.activeItem; // active comp
if (comp instanceof CompItem) {
var selectedProperties = comp.selectedProperties;
var property = selectedProperties[0];
var amLay = app.project.activeItem.layers.length;
var comp = app.project.activeItem;
var layers = comp.selectedLayers;
var layer = layers[0];
var selectedProperties = comp.selectedProperties;
var property = selectedProperties[0];
var propPath = getPropPath(property);
var prop = eval(“layer.property” + getPropPath(property));
function getPropPath(prop) {
var layerRoot = false;
var propPath = “”;
while (prop.parentProperty) {
propPath = “(‘” + prop.name + “‘)” + propPath;
prop = prop.parentProperty;
}
return propPath;
}
function easeLayer() {
for (var a = 1; a <= amLay; a++) {
//~ if (proEx == null) continue; this is the if statement that dismantles the function
var proEx = eval(“app.project.activeItem.layer(” + a + “)” + propPath + “.setInterpolationTypeAtKey(1,KeyframeInterpolationType.HOLD);”);
}
};
easeLayer();
};