Search code examples
adobeextendscripttextselectionafter-effects

How can I programmatically get text selection in Adobe After Effects with ExtendScripts


I have object TextLayer with white text color string. Then I animate text color selection (second character changes color white -> blue).

How can I get this selection and color programmatically?


Solution

  • Seems like you can't reach the selection start and end values by scripting. But you can add expression controller effect and get the values from that one.

    1. The code below asumes you have one comp in your project with an text layer called "my text layer".
    2. Add an expression controller for color to that layer. Add the expression text.animator("Animator 1").property.fillColor to that effect.

    You can do the same thing with the values from your selection.

    var preExpression = true;
    var currentTime = 5; // in seconds
    // get the sourceText? works!
    var val = app.project.item(1).layer("my text layer").property("ADBE Text Properties").property("ADBE Text Document").valueAtTime(currentTime, preExpression);
    // get the Text Percent Start? Wont work!
    var sel = app.project.item(1).layer("my text layer").property("ADBE Text Properties").property("ADBE Text Animators").property("ADBE Text Animator").property("ADBE Text Selectors").property("ADBE Text Selector").property("ADBE Text Percent Start").valueAtTime(currentTime, preExpression);
    // add an expression controller for color and get the color from that one? works!
    var col = app.project.item(1).layer("my text layer").property("ADBE Effect Parade").property("ADBE Color Control").property("ADBE Color Control-0001").valueAtTime(currentTime, false);
    $.writeln(val);
    $.writeln(sel);
    $.writeln(col);
    

    Take a look into the After Effects Scripting Guide. Use redefinery's rd_GimmePropPath script to get the match names of properties.