Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Can someone point me in the right direction for this?

  • Can someone point me in the right direction for this?

    Posted by Darryl Torke on April 16, 2014 at 11:09 pm

    I am wondering if there is an script that can do this:

    find the height and width of a text layers bounding box,
    then accordingly scale it to fit in title safe and centre it horizontally and vertically.

    I believe the solution is scripting, but I’m still not sure where to look. If anyone has information I could look at that would be great.

    Thank you in advance.

    Darryl Torke replied 12 years, 1 month ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    April 17, 2014 at 12:46 am

    This assumes that the text is layer 1 and the comp is selected:


    var myComp = app.project.activeItem;
    var myLayer = myComp.layer(1);
    var myRect = myLayer.sourceRectAtTime(0,true);

    if (myRect.width/myComp.width > myRect.height/myComp.height){
    var scaleFactor = myComp.width*.8/myRect.width;
    }else{
    var scaleFactor = myComp.height*.8/myRect.height;
    }

    var p = myLayer.property("Position").value;
    var s = myLayer.property("Scale").value;
    var newS = [s[0]*scaleFactor,s[1]*scaleFactor];
    myLayer.property("Scale").setValue(newS);

    var leftEdge = p[0] + myRect.left*newS[0]/100;
    var topEdge = p[1] + myRect.top*newS[1]/100;

    deltaX = (myComp.width - myRect.width*newS[0]/100)/2 - leftEdge;
    deltaY = (myComp.height - myRect.height*newS[1]/100)/2 - topEdge;

    myLayer.property("Position").setValue([p[0]+deltaX,p[1]+deltaY]);

    Dan

  • Darryl Torke

    April 17, 2014 at 7:17 pm

    Wow! Thanks very much Dan. It works great.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy