Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

After effect scripting set text bounds

Community Beginner ,
Oct 14, 2022 Oct 14, 2022

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;

TOPICS
Scripting
622
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Oct 14, 2022 Oct 14, 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

Translate
Community Beginner ,
Oct 14, 2022 Oct 14, 2022

Forgot to add image .this is the image 
Screenshot 2022-10-15 115851.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 15, 2022 Oct 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);
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 14, 2022 Oct 14, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 15, 2022 Oct 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

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 15, 2022 Oct 15, 2022
LATEST

Thanks It was really helpfull.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 15, 2022 Oct 15, 2022
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 15, 2022 Oct 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines