Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Using sourceRectAtTime and if/else

  • Using sourceRectAtTime and if/else

    Posted by Chris Stetson on November 16, 2018 at 5:00 pm

    Hello,

    I’m new here and trying to figure out how to combine the use of sourceRectAtTime with if/else.

    I have two text layers on top of a shape layer. I’d like the shape layer width to adjust based on whichever text layer has the greatest width. Below is the expression I’ve written and I am not getting any errors, but the if/else statement doesn’t seem to be working. The shape layer adjusts based on the first text layer, but if the second text layer is greater than the first, it does not adjust accordingly. Any help would be greatly appreciated. Thank you.

    Chris Stetson

    var A = thisComp.layer("NAME");
    var W1 = A.sourceRectAtTime().width;
    var B = thisComp.layer("Title");
    var W2 = B.sourceRectAtTime().width;
    var Y = content("Rectangle 1").content("Rectangle Path 1").size[1]
    var P = thisComp.layer("Control").effect("Text Padding")("Slider");

    if(W1>W2){
    W1
    }else{
    W2
    }

    [W1||W2,Y]+[P+P];

    Geoffrey Amend replied 7 years, 4 months ago 3 Members · 3 Replies
  • 3 Replies
  • Dan Ebberts

    November 16, 2018 at 5:24 pm

    I’d do something like this:

    var A = thisComp.layer(“NAME”);
    var W1 = A.sourceRectAtTime().width;
    var B = thisComp.layer(“Title”);
    var W2 = B.sourceRectAtTime().width;
    var Y = content(“Rectangle 1”).content(“Rectangle Path 1”).size[1]
    var P = thisComp.layer(“Control”).effect(“Text Padding”)(“Slider”);

    W = Math.max(W1,W2);

    [W,Y]+[P,P];

    Dan

  • Chris Stetson

    November 16, 2018 at 6:58 pm

    Dan! Thanks so much for your help. That did it. I had to modify slightly since this caused the height to change, which I wanted it to stay constant, but I was able to fix that. Thanks again for your help.

    var A = thisComp.layer("NAME");
    var W1 = A.sourceRectAtTime().width;
    var B = thisComp.layer("Title");
    var W2 = B.sourceRectAtTime().width;
    var Y = 380
    var P = thisComp.layer("Control").effect("Text Padding")("Slider");

    W = Math.max(W1,W2);

    [W,Y]+[P,0];

  • Geoffrey Amend

    January 2, 2019 at 12:15 am

    Hi. I’m tryin to apply this to a template that will include either 2 or 3 lines of text. But my question I think is regarding an expression I can add to the slider as I need the padding to be as follows:

    Z= the height of the font

    top edge and bottom edge of shape = 2/3 of Z
    left padding = Z
    distance between text layers = 1/2 Z

    And finally, the right edge of shape won’t be a vertical line as in a rectangle but a 60 degree angle from lower right to upper right and the padding on the lower right will need to also be determined relative to Z….

    Any help is greatly appreciated. Thanks very much.

    Thank you!

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