Skip to content
fabiantheblind edited this page May 9, 2016 · 2 revisions

A simple example that sets the sourceText property of a new layer each frame.

/**
 * main function
 */
var main = function() {
  var txt = ['Hello - World', 'dog - cat', 'foo - bah']; // the text to add
  app.beginUndoGroup('add source text'); // open a undo group
  var curComp = app.project.activeItem; // get the current comp
  // check if the curent active item is a comp
  if (!curComp || !(curComp instanceof CompItem)) {
    alert('noComp');
    return;
    // end if no comp is active
  }
  var txtLayer = curComp.layers.addText('titles'); // add a text layer
  var counter = 0; // the time to add a keyframe to (in seconds)
  // loop the text
  for (var i = 0; i < txt.length; i++) {
    var curFrame = (counter / curComp.frameRate); // calc time for each frame
    $.writeln(curFrame);
    // add a keyframe with the text as value every frame
    txtLayer.text.sourceText.setValueAtTime(curFrame, txt[i]);
    counter++; // increase the time by one
  }
  app.endUndoGroup();
};
main();
Clone this wiki locally