I'm trying to do something relatively simple, but am having trouble figuring out why it's not working. I want a script that scales a text layer to the correct size so that it fits the extents of its parent comp. I have found a couple of resources that do this, but I think these scripts assume that AE is running with its GUI. In my case, I'm running afterfx.exe from a batch script with the -noui switch. So, when running AE with the -noui switch, it seems that using the app.executeCommand() function doesn't seem to work right. Here are the threads I found for handling exactly what I want, but that both incorporate the app.executeCommand() method:
Does anybody have any other suggestions for writing a script that fits a text layer to size, or are these the only alternatives out there?
Thank you for your time and help!
You don’t need to use app.executeCommand() for that any more. Something like this should work:
var myComp = app.project.activeItem;
var myLayer = myComp.layer(1);
var myRect = myLayer.sourceRectAtTime(0,false);
var myScale = myLayer.property("Scale").value;
var myNewScale = [myScalemyComp.width/myRect.width,myScalemyComp.height/myRect.height];
Thank you Dan for that code, it helped tremendously. Is there any way to ensure that the X & Y values of the scale are locked in proportion to one another. My apologies for not being clear in my initial post: I want to fit the text layer to the extents of its parent comp while ensuring its width:height proportions stay intact.
I think you just need to change one line:
var myNewScale = myScale*Math.min(myComp.width/myRect.width,myComp.height/myRect.heigh t);
Edit: There's an extra space in the last word and I can't seem to edit it out. You'll figure it out.. :-)