-
AE Script to Scale Font size to addBoxText
I’m trying to come up with a script that will create text layers, and then size the font within it appropriately to fit to the width of the box. I have searched a bunch and (slightly) modified another script to get me started. It can successfully open a txt file and create the layers from each line, but since they are all set to the default font and font size, if the text on the line is too long it wraps it to a second line, whereas I would like it to decrease the size until it fits on one line. Once I get all the sorted out I will be trying to configure it to possibly add a bit of padding and center it in the composition. Most of the research I’ve done has referred to using a hack-around of sample image, but this generally seems to be outdated as scripts have access to text-properties. If anyone could point me in the right direction it would make my life way easier. The code so far is below, and thanks in advance!
//
// createTextLayersFromFile.jsx
////
// This script reads a user specified text file and
// creates a text layer for each line of text in a
// new comp called "my text comp"
//{
// create undo group
app.beginUndoGroup("Create Text Layers From File");
// Prompt user to select text file
var myFile = File.openDialog("Please select input text file.");
if (myFile != null){// open file
var fileOK = myFile.open("r");
if (fileOK){// read text lines and create text layer for each
// until end-of-file is reachedvar myComp = app.project.activeItem;
var text;
while (!myFile.eof){
text = myFile.readln();
compW = myComp.width
compH = myComp.height
if (text == "") text = "\r" ;
myComp.layers.addBoxText([compW, compH], text);
}// close the file before exiting
myFile.close();
}else{
alert("File open failed!");
}}else{
alert("No text file selected.");
}app.endUndoGroup();
}