-
Ae Script: Adding generated layer to selected layers
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 < 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 < 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++;
}