Copy link to clipboard
Copied
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;
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
Copy link to clipboard
Copied
Forgot to add image .this is the image
Copy link to clipboard
Copied
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);
}
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
paragraph text ?
All could found is text document
https://ae-scripting.docsforadobe.dev/other/textdocument.html.
Could you please refer me some docs
Copy link to clipboard
Copied
Thanks It was really helpfull.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
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: