Activity › Forums › Adobe After Effects Expressions › Creating a textbox and align it to an area via extendscript
-
Creating a textbox and align it to an area via extendscript
Posted by Emre Mutlu on June 28, 2022 at 7:05 pmHi there,
How can i create a text box in a composition and center it to specific area? (Like the example in the attachment)
Emre Mutlu replied 3 years, 10 months ago 3 Members · 4 Replies -
4 Replies
-
Filip Vandueren
June 30, 2022 at 8:01 pmHi Emre,
to my knowledge it’s still not possible to create textbox-textlayers via scripting, only paragraph text.
You can only check if a textlayer is a text-box and get its dimensions/position, not set the properties.
https://www.youtube.com/watch?v=6P76aFYmOR8
Some contents or functionalities here are not available due to your cookie preferences!This happens because the functionality/content marked as “Google Youtube” uses cookies that you choosed to keep disabled. In order to view this content or use this functionality, please enable cookies: click here to open your cookie preferences.
-
Dan Ebberts
June 30, 2022 at 9:04 pmScripting does have a command specifically for creating box text, so you could do something like this to create the text and center the anchor point within the resulting text (which will be centered within the comp):
var myComp = app.project.activeItem;
var myTextLayer = myComp.layers.addBoxText([300,500]);
var mySourceText = myTextLayer.property("ADBE Text Properties").property("ADBE Text Document");
var myTextDoc = mySourceText.value;
myTextDoc.text = "This is a line of text for my new text box.";
myTextDoc.justification = ParagraphJustification.CENTER_JUSTIFY;
mySourceText.setValue(myTextDoc);
var myRect = myTextLayer.sourceRectAtTime(0,false);
var newAP = [myRect.left + myRect.width/2, myRect.top + myRect.height/2];
myTextLayer.property("Anchor Point").setValue(newAP);
-
Filip Vandueren
June 30, 2022 at 11:22 pmThat’s great. I don’t script often and have always missed this. Thanks Dan.
-
Emre Mutlu
July 1, 2022 at 7:34 amThank you very much guys. I was having trouble to change style of the text box which i’ve added but figure it out too. I’m adding my code here too. Looks like you should use TextDocument object to modify the style of text box.
var titleLayer = mainComp.layers.addBoxText([1250,500]);
// Title Text Properities ///////////////////////////////////////////
var titleTextDoc = new TextDocument(“Test Text”);
titleLayer.property(“Source Text”).setValue(titleTextDoc);
var textProp = titleLayer.property(“Source Text”);
titleTextDoc = textProp.value;
titleTextDoc.fontSize = 50;
titleTextDoc.text = title;
titleTextDoc.fillColor = [1,0,0];
titleTextDoc.justification = ParagraphJustification.CENTER_JUSTIFY;
textProp.setValue(titleTextDoc);
Reply to this Discussion! Login or Sign Up