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

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