Jonathan Leger
Jonathan Leger

Reputation: 83

How do you change the color of a text layer in After Effects 2017 using ExtendScript?

I need to know how to change the color of a text layer in After Effects 2017 using ExtendScript. I can change the text itself very simply, like so:

var comp=app.project.item(10);
comp.layer(1).property('Source Text').setValue('My Text Here');

But how do I set the color of that text layer? I would think this would be very simple but despite much searching I haven't found anything that clearly explains how to do this.

Thanks in advance!

Upvotes: 0

Views: 4238

Answers (1)

stib
stib

Reputation: 3512

Page 182 of the After Effects CS6 Scripting guide (the most recent documentation that Adobe have deigned to give us) describes the TextDocument object, which is the data type for a text layer's Source Text property. Amongst the attributes is fillColor and strokeColor.

edit it's not as simple as it seems, you can't just assign the values to the source text, you have to make a new textDocument object, make your changes to it, and then assign the value of the source text property to the textDocument object you created.

So you can set it thus:

var textProp = comp.layer(1).property('Source Text');
//make a new textDocument, copying the values of the current one
var textDocument = textProp.value;
// change any attributes of the textDocument here, e.g.:
textDocument.fillColor = [R, G, B];
// write the textDocument over the existing one
textProp.setValue(textDocument);

R, G and B are floating-point values, where 1.0 ⇒ 255 in 8-bit colour.

You can also see that scripting guide online at aeenhancers There's a typo where it describes the constructor, it says newTextDocument it should be new TextDocument

Upvotes: 1

Related Questions