After Effects scripts: How to add Composition with start time display to an Composition

Viewed 1521

I have three compositions (compFinal, compSlide1 and compSlide2).

I have used a script to add compSlide1 and compSlide2 to the compFinal composition.

I use the following code to add the compositions:

compFinal.layers.add(compSlide1); 
compFinal.layers.add(compSlide2); 

But when inserting them in compFinal both compositions compSlide1 and compSlide2 will have the same start-time "0".

When adding composition compSlide2 I want it so that I can set the start-time displayed for composition 2 equal the end-time of compSlide1

enter image description here

1 Answers

It will depend partly on the complexity of your layers, but you can use the startTime property of current layer combined with the outPoint to adjust the layers to follow each other.

A simple loop can help in that regard, run after all the layers are added (in order):

// initial time (in seconds)
var time = 0;

// loop through all layers in comp
for(var i = 1; i <= finalComp.layers.length; i++) {

    // set layer startTime based on current time value
    finalComp.layers[i].startTime = time;

    // update time to hold outPoint time of this layer
    // which will next layer's start time
    time = finalComp.layers[i].outPoint;
}

If you only have two layers just set the second layer to start from previous layer's out-point:

finalComp.layers[2].startTime = finalComp.layers[1].outPoint;
Related