Programmatically change the text of a TextLayer in After Effects
Asked Answered
R

4

5

I'm using the After Effects CS3 Javascript API to dynamically create and change text layers in a composition.

Or at least I'm trying to because I can't seem to find the right property to change to alter the actual text of the TextLayer object.

Rally answered 16/9, 2008 at 4:44 Comment(0)
R
4

Hmm, must read docs harder next time.

var theComposition = app.project.item(1);
var theTextLayer = theComposition.layers[1];
theTextLayer.property("Source Text").setValue("This text is from code");
Rally answered 16/9, 2008 at 14:41 Comment(0)
S
2

I'm not an expert with After Effects, but I have messed around with it. I think reading this might help you out.

Spanking answered 16/9, 2008 at 4:49 Comment(0)
C
1

This is how I'm changing the text.

var comp = app.project.item(23);
var layer = comp.layer('some_layer_name');
var textProp = layer.property("Source Text");
var textDocument = textProp.value;

textDocument.text = "This is the new text";
textProp.setValue(textDocument);
Consociate answered 4/3, 2015 at 2:0 Comment(0)
S
0

I wrote a simple function for myself to change properties. Here it is:

function change_prop(prop, name, value){
    var doc = prop.value;

    doc[name] = value;
    prop.setValue(doc);

    return prop;
}

Example use:

// Changing source text
change_prop(text_layer.property("Source Text"), "text", "That's the source text");

// Changing font size
change_prop(text_layer.property("ADBE Text Properties").property("ADBE Text Document"), "fontSize", 10)
Stirling answered 25/1, 2020 at 22:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.