javascriptadobeextendscriptafter-effects

How to create a text box in After Effects using ExtendScript?


I'm trying to create a text box in after effects using extendscript, like the text box when you use the text tool and click and drag a box. Every resource I can find only shows how to make an actual box around text, but I just want the text box so that the text wraps and doesn't go outside the bounds of the composition when using a large font size. Here's what I have so far:

function createText(text, startTime, endTime, font)
{
var textLayer = newComp.layers.addText(text);
var sourceText = textLayer.property("Source Text").value;
sourceText.fontSize = 200;
sourceText.font = font;
textLayer.property("Source Text").setValue(sourceText);
textLayer.startTime = startTime;
textLayer.inPoint = startTime;
textLayer.outPoint = endTime;
var textRect = textLayer.sourceRectAtTime(0,false);
textLayer.property("Position").setValue([newComp.width/2,newComp.height/2]);
textLayer.property("Scale").setValue([100,100]);
}

The kind of text box I'm trying to create: Text Box


Solution

  • To create a Paragraph (box) Text layer use the addBoxText() method rather than addText(). This takes the parameters [width, height] which specify the size of the text box.

    You can read the docs here