Skip to main content
online1234
Participant
November 1, 2014
Answered

How to add text animator to text layer in script?

  • November 1, 2014
  • 2 replies
  • 4529 views

Hello,

I'm a beginner in scripting and trying to create a script to apply set of expression control and text animator.

I want to add text animator property to selected layer, however I keep having error with the codes below.

selectedLayers[0].Text.Animators.addProperty("ADBE Text Animator");

selectedLayers[0].Text.Animators.addProperty("ADBE Text Position");    //error on this line


What is the correct code?


Thanks a lot.

This topic has been closed for replies.
Correct answer Dan Ebberts

This might be what you need:

var myAnim = selectedLayers[0].Text.Animators.addProperty("ADBE Text Animator");

myAnim.property("ADBE Text Selectors").addProperty("ADBE Text Selector");

myAnim.property("ADBE Text Animator Properties").addProperty("ADBE Text Position 3D");

Dan

2 replies

PetePLTR
Participating Frequently
February 13, 2024

I'm also trying to do this at the moment & stuck!

 

I have...

 

function createLabelsTextLayer(comp, labels) {

  var textLayer = comp.layers.addText("Labels");

  textLayer.name = "Labels";

  var textProp = textLayer.property("Source Text");

  var expression = '["' + labels.join('", "') + '"]';

  textProp.expression = expression;

 

  // Create a single position animator

  var myAnim = textLayer.Text.Animators.addProperty("ADBE Text Animator");

  myAnim.property("ADBE Text Animator Properties").addProperty("ADBE Text Position");

  myAnim.property("ADBE Text Selectors").addProperty("ADBE Text Expressible Selector");

 

I get this error...

Unable to execute script at line 60. After Effects error: Can not add a property with

name "ADBE Text Position" to this PropertyGroup.

 

Any ideas?

 

 

 

 

Legend
February 13, 2024

@PetePLTR 

replace ADBE Text Position with ADBE Text Position 3D

PetePLTR
Participating Frequently
February 13, 2024

ha! we crossed streams! Just figured it out.

The scripting documentation sucks.

Thanks!

 

Dan Ebberts
Community Expert
Community Expert
November 1, 2014

Try it this way:

var myAnim = selectedLayers[0].Text.Animators.addProperty("ADBE Text Animator");

myAnim.property("ADBE Text Animator Properties").addProperty("ADBE Text Position 3D");

Dan

online1234
Participant
November 1, 2014

Thanks Dan, that works!

However, I hit another road block. I tried to add a range selector under the animator group with the codes below and both returned error.


myAnim.property("ADBE Text Animator Properties").addSelector("ADBE Text Range Selector");

myAnim.property("ADBE Text Animator Properties").addProperty("ADBE Text Range Selector");

After reading this post. how to access text proprety

Its seem text animator has different codes for accessing different properties.

I've searched on the Adobe scripting guide and couldn't find the exact code for the property (e.g. ADBE Text Position 3D ).

It would be much appreciated If anyone could recommend a scripting book for After Effects.

Thanks.

Dan Ebberts
Community Expert
Community Expert
November 25, 2023

Oh, got it! That version was a huge mess! After using "rd_GimmePropPath" script i was able to track those paths down. Here´s the final version. Its for subtitling music videos. Is a typewriter effect that shows word by word, speed based on layer length, so after captions ready on premiere,  i import SRT into AE, then apply this script on all layers. Here´s the script for those who may need it. Cheers! I will keep cleaning it. Any thoughts on it, Dan? 

_______________________________________

// Apply Opacity Animator with Expression to Selected Text Layers
var comp = app.project.activeItem;

if (comp && comp instanceof CompItem) {
var selectedLayers = comp.selectedLayers;

if (selectedLayers.length > 0) {
app.beginUndoGroup("Apply Opacity Animator with Expression");

for (var i = 0; i < selectedLayers.length; i++) {
var currentLayer = selectedLayers[i];

// Check if the layer is a text layer
if (currentLayer instanceof TextLayer) {

// Add Opacity Animator
var textProperties = currentLayer.property("Text");
var animatorsGroup = textProperties.property("Animators");
var opacityAnimator = animatorsGroup.addProperty("ADBE Text Animator");


// Add Opacity Property
var opacityProperty = opacityAnimator.property("ADBE Text Animator Properties").addProperty("ADBE Text Opacity");


// Set Range Selector
var rangeSelector = opacityAnimator.property("ADBE Text Selectors").addProperty("ADBE Text Selector");
rangeSelector.property("Start").expression =
"textLayer = thisComp.layer(\"" + currentLayer.name + "\");" +
"layerLength = textLayer.outPoint - textLayer.inPoint;" +
"mappedValue = linear(time, textLayer.inPoint, textLayer.outPoint, 0, 100);" +
"clampedValue = clamp(mappedValue, 0, 100);" +
"clampedValue;";

// Set advanced

rangeSelector.advanced.units.setValue(1); // percentage
rangeSelector.advanced.smoothness.setValue(0);
rangeSelector.advanced.basedOn.setValue(3);

// Set Opacity

currentLayer.text.animator(1)("ADBE Text Animator Properties").opacity.setValue(0);



}
}

app.endUndoGroup();
} else {
alert("Please select at least one text layer.");
}
} else {
alert("Please open a composition.");
}

_____________________________________________________

Everton.


It looks pretty good. If you intend for other people to use it, I'd switch everything to match names so it isn't language-dependant. Also, I think you could simplify your expression to this:

 

rangeSelector.property("Start").expression = "linear(time,inPoint,outPoint,0,100)";