Skip to main content
madhawap70708962
New Participant
October 15, 2022
Answered

After effect scripting set text bounds

  • October 15, 2022
  • 4 replies
  • 674 views

I'm trying to generate text layers dinamically using a script.It works well.I coudn't find a way to contain the text without overflowing .As you can see in this image text is gone out of the composition view.

I trid to set a width but it doesn't work .Any idea about this.

var textLayer = comp.layers.addText(text);
textLayer.sourceRectAtTime(inPoint, false).width=1000;

This topic has been closed for replies.
Correct answer Mylenium

You will have to create paragraph text, not line-based text. Otherwise you have to do your own calculations to adjust size or wrap lines around. The text bounding box has nothing to do with this.

 

Mylenium

4 replies

Mathias Moehl
Community Expert
October 15, 2022

You can also apply an expression to the layer scale, which scales the layer down when the source text goes beyond a certain size.

In the Community Library of Automation Blocks we have a tool which creates such expressions:

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
Mylenium
Brainiac
October 15, 2022
Mylenium
MyleniumCorrect answer
Brainiac
October 15, 2022

You will have to create paragraph text, not line-based text. Otherwise you have to do your own calculations to adjust size or wrap lines around. The text bounding box has nothing to do with this.

 

Mylenium

madhawap70708962
New Participant
October 15, 2022

paragraph text ?
All could found is text document 
https://ae-scripting.docsforadobe.dev/other/textdocument.html.

Could you please refer me some docs

 

madhawap70708962
New Participant
October 15, 2022

Forgot to add image .this is the image 

Dan Ebberts
Community Expert
October 15, 2022

This will adjust the font size to fit within a maximum width:

var text = "this is a long text testing scripting";
var comp = app.project.activeItem;
var maxWidth = comp.width;
var textLayer = comp.layers.addText(text);
var w = textLayer.sourceRectAtTime(textLayer.inPoint, false).width;
if (w > maxWidth){
	var sourceText = textLayer.text.sourceText;
	var textDoc = sourceText.value;
	textDoc.fontSize *= maxWidth/w;
	sourceText.setValue(textDoc);
}