I am just learning AE Scripting, and this is my first script. It took a while, and I eventually got it to do what I wanted it to, but I am now having an issue with the Undo Group. When I run the script it gives me an 'Undo Group Mismatch' and fails to completely undo the actions in the script. I'm afraid I'm not knowledgeable enough to determine the source of the problem. I'd appreciate any help.
The script creates a solid, applies the Gradient Ramp, then Copies it with Property Links, Pastes it, then pre-comps the copy. Then on the master solid it adds a camera blur, sets the pre-comp to the blur layer, and hides the main gradient ramp effect. The idea being I can still control the ramp from the main timeline and it is mirrored in the pre comp. Here's the script:
- /* DOF script
- Make a solid called 'DOF_Master'
- Apply Gradient Ramp
- Copy With Properties
- Paste as 'DOF_Slave'
- Pre-Comp as 'DOF_Slave Comp'
- Move Slave to bottom of layer stack
- To Master: Apply Camera Blur
- Turn Gradient Ramp off
- Select slave Comp as Blur Layer
- Set as Adjustment layer
- */
- app.beginUndoGroup("DOF with Precomped Gradient");
- function createDOF(){
- // variables
- var myComp = app.project.activeItem;
- if(myComp == null){alert("Please, select your composition"); return false;}
- var slaveIndex
- var w = myComp.width ;
- var h = myComp.height ;
- // create solid at comp dimensions
- myComp.layers.addSolid([1.0,1.0,0], "DOF_Master", w, h, 1);
- // Apply Ramp and Camera Blur filters
- myComp.layer("DOF_Master").Effects.addProperty("ADBE Ramp");
- // Copy layer with Property Links
- app.executeCommand(10310);
- // Paste layer
- app.executeCommand(20);
- // Rename
- myComp.layer("DOF_Master 2").name = "DOF_Slave";
- //Pre Compose Slave, hide and move to bottom of layers
- slaveIndexA = myComp.layer("DOF_Slave").index
- myComp.layers.precompose([slaveIndexA],"DOF_Slave Comp","True");
- myComp.selectedLayers[0].enabled = false;
- myComp.selectedLayers[0].moveToEnd();
- slaveIndex = myComp.layer("DOF_Slave Comp").index
- //add Camera Blur, set effect properties to Master Layer and make adjustment layer
- myComp.layer("DOF_Master").effect("Gradient Ramp").enabled = false
- myComp.layer("DOF_Master").Effects.addProperty("ADBE Camera Lens Blur");
- myComp.layer("DOF_Master").effect("Camera Lens Blur").property("Layer").setValue(slaveIndex);
- myComp.layer("DOF_Master").effect("Camera Lens Blur").property("Invert Blur Map").setValue(true);
- myComp.layer("DOF_Master").adjustmentLayer = true
- myComp.layer("DOF_Master").selected = true
- myComp.layer("DOF_Slave Comp").selected = false
- }
- createDOF();
- app.endUndoGroup();