ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Ae Script: Adding generated layer to selected layers

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Mike Pindara
Ae Script: Adding generated layer to selected layers
on Oct 24, 2016 at 5:07:26 pm

Hey folks,

I'm writing a script for some project management things in the studio I work at.
I've got everything working except the most important part.

With the selected layers, the script should create a precomp of the selected layers, and the duplicate of a master layer that is at the bottom of the comp. Right now, everything gets duplicated correctly, and precomped and trimmed correctly. I just can't figure out how to add the duplicated layer into the selected array, so that it gets precomped as well.

Any help? I posted the function below.

function precompGroup(userLayers){
// create undo group
app.beginUndoGroup("Pre-Compose to Layer Duration");

// select the active item in the project window
// and make sure it's a comp
var myComp = userLayers;
if(myComp instanceof CompItem) {

// make sure one or more layers are selected
var myLayers = myComp.selectedLayers;
if(myLayers.length > 0){

// set new comp's default in and out points to those of first layer
var newInPoint = myLayers[0].inPoint;
var newOutPoint = myLayers[0].outPoint;

//ensure master audio exists
if(masterAudio instanceof CompItem){

// create new comp name of "Scene " and global variable
var newCompName = "Scene ";
newCompName += currentShot;

// "precompose" expects an array of layer indices
var layerIndices = new Array();
for (var i = 0; i &lt; myLayers.length; i++) {
layerIndices[layerIndices.length] = myLayers[i].index;

// make sure new comp in point is in point of earliest layer
// and new comp out point is out point of latest layer
if (myLayers[i].inPoint &lt; newInPoint) newInPoint = myLayers[i].inPoint;
if (myLayers[i].outPoint > newOutPoint) newOutPoint = myLayers[i].outPoint;
}

//create ref audio layer
var origAudio = app.project.activeItem.layer("0_Master Audio");
var refAudio = origAudio.duplicate();
refAudio.inPoint = newInPoint;
refAudio.outPoint = newOutPoint;

//addRef Audio to selected Layers


//add index to layerIndicies


// create the new comp
var newComp = myComp.layers.precompose(layerIndices, newCompName, true );

// set in and out points of new comp
var preCompLayer = myComp.selectedLayers[0];
preCompLayer.inPoint = newInPoint;
preCompLayer.outPoint = newOutPoint;

currentShot++;

}


Return to posts index

Miguel de Mendoza
Re: Ae Script: Adding generated layer to selected layers
on Oct 25, 2016 at 9:23:57 am

If that master layer is at the bottom of layers you can get his index like this:

var bottomLayerIndex = myComp.layer(myComp.layers.length).index;

If that layer have a concrete name:

var bottomLayerIndex = myComp.layers.byName(yourMasterLayerName).index;

Then you can push it into the array:

layerIndices.push(bottomLayerIndex);


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 CreativeCOW.net All Rights Reserved
[TOP]