SmIqbal
SmIqbal

Reputation: 99

sourceText value through script

Any idea why below two lines are not being executed in After Effects? In first line, I simply want to show source text value through an alert. In second line, I want to select layer number with index value of 2.

alert(app.project.activeItem.layer(2).sourceText.value)

app.project.activeItem.layer(2).selected = true;

I am getting Undefined error in console. Both seem to be very basic tasks but I am not being able to figure it out.

Thanks.

Upvotes: 2

Views: 1749

Answers (1)

Ziki
Ziki

Reputation: 1440

To access the text document value of text layer you need to call it in this way:

var textDocument = app.project.activeItem.layer(2).text.sourceText.value;

Then to get the value of the text document (the actual text) you need to get the text property:

var text = textDocument.text;

The text document object contains (almost) all properties of the text layer.

The 2nd line should work properly. Probably it didn't fired because the script failed on the 1st line.

If you want to deselect all layers before, you need to loop all the selected layers and deselect them. You can do it with this code:

var comp = app.project.activeItem;
var selectedLayers = comp.selectedLayers;
for (var i = 0; i < selectedLayers.length; i++) {
    selectedLayers[i].selected = false;
}

Upvotes: 3

Related Questions