// // preCompToLayerDur.jsx (revised 12th June 2008) // // This script will pre-compose selected layers with "Move all attributes..." // The selected layers will be moved in time to begin at the start of the new pre-comp // The pre-comp will begin at the original in-time of the earliest layer // Based on an idea by Brian Maffitt // Original code design by Keiko Yamada // Major tweaks and enhancements by Dan Ebberts // Minor tweak (moving in-times) by Chris Zwar { // 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 = app.project.activeItem; 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; // create new comp name of "comp " plus name of first layer var newCompName = "Precomp-Layer"; var layerName = myLayers[0].index; if(layerName.length > 26) { layerName = layerName.substring(0, 26); } newCompName += layerName; // "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; } // move the selected layers to the start of the comp // now that we have recorded their original in-points for (var i = 0; i < myLayers.length; i++) { myLayers[i].startTime = myLayers[i].startTime - newInPoint; } // create the new pre-comp var newComp = myComp.layers.precompose(layerIndices, newCompName, true ); // make the duration of the new pre-comp match the selected layers var preCompLayer = myComp.selectedLayers[0]; preCompLayer.inPoint = 0; preCompLayer.outPoint = newOutPoint-newInPoint; preCompLayer.startTime = newInPoint; }else{ alert("select at least one layer to precompose."); } }else{ alert("please select a composition."); } app.endUndoGroup(); }