ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Using sourceRectAtTime and if/else

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Chris Stetson
Using sourceRectAtTime and if/else
on Nov 16, 2018 at 5:00:28 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];


Return to posts index

Dan Ebberts
Re: Using sourceRectAtTime and if/else
on Nov 16, 2018 at 5:24:04 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



Return to posts index

Chris Stetson
Re: Using sourceRectAtTime and if/else
on Nov 16, 2018 at 6:58:49 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];


Return to posts index


Geoffrey Amend
Re: Using sourceRectAtTime and if/else
on Jan 2, 2019 at 12:15:04 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!


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 CreativeCOW.net All Rights Reserved
[TOP]