-
AE Script for creating/adding layers
I’m creating a script that creates a solid layer, applies a Fractal Noise effect, then precomposes the layer.
var proj = app.project;
var comp = proj.items.addComp(name, 1920, 1080, 1.0, 30.0, 29.97);var distortionLayer = comp.layers.addSolid([0, 0, 0], 'Distortion', 1920, 1080, 1.0);
distortionLayer.Effects.addProperty("ADBE Fractal Noise");
distortionLayer.enabled = false;
comp.layers.precompose([1], 'jj_Distortion', true);Now this is fine for one comp, but if the script is run again, it will simply create another “jj_Distortion” comp. Instead, I want to check if the “jj_Distortion” comp exists. If it does, then add it to the current comp. Else, create the comp.
I know the example below is not code, but I’m thinking it could look like this:
if(layer("jj_Distortion").exists()){
//Add the jj_Distortion comp to this comp
} else {
// Create it
var distortionLayer = comp.layers.addSolid([0, 0, 0], 'Distortion', 1920, 1080, 1.0);
distortionLayer.Effects.addProperty("ADBE Fractal Noise");
distortionLayer.enabled = false;
comp.layers.precompose([1], 'jj_Distortion', true);
}I’ve gone through the CS6 Scripting guide, but I can’t find the correct command(s) there or through Google.
Any help would be greatly appreciated.