Copy link to clipboard
Copied
Trying to add functionality to a basic MOGRT and I'm really rough with expressions.
On top of this graphic is a line of text (master property, in this case layer XXX).
This code is on a white box that will expand/contract it's width based on length of text in XXX.
Found out that this would work:
L= thisComp.layer("XXX");
X= L.sourceRectAtTime().width*.7; /*as the string of text in XXX gets longer, needed a multiplier to tighten up the padding... 0.7 works fro the range of possible text*/
Longer=X+8; /*needed to give some padding when XXX is just a single "i"*/
Y=100;
[Longer,Y];
So, this works great... except when there is NO text in the XXX layer.
It returns the 8. Which creates a thin white backgorund box.
What I think would work; add another variable "P" for padding.
P= if(L.sourceRectAtTime().width)>0){8}else{0}; /*this is saying 'illegal use of if'*/
and then I would change this line Longer=X+P;
Try replacing your second line with:
P = L.sourceRectAtTime().width > 0 ? 8 : 0;
Dan
Copy link to clipboard
Copied
Nothing wrong with the code per se, you just threw in one too many closing parentheses. Remove the one ) after .width and everything will work.
Mylenium
Copy link to clipboard
Copied
Error: Illegal use of reserved word 'if'
Copy link to clipboard
Copied
Is there something else I need to typ to start the if/else math? ...seems to get hun up on "illegal use of 'if' "
Copy link to clipboard
Copied
That's funky, but perhaps simply filling in the relevant paramters to sourceRectAtTime() might fix it. Also, now that I have a second look, you are also of course creating a cyclic condition. I mean, if the rectangle is zero, anyway, then there's no reason to double-zero your variable P. Or in other words: You are using the testing condition also for the output value, which makes no real sense. In fact that could be the actual error. A source rectangle of zero width cannot exist, anyway.
Mylenium
Copy link to clipboard
Copied
Try replacing your second line with:
P = L.sourceRectAtTime().width > 0 ? 8 : 0;
Dan
Copy link to clipboard
Copied
THANK YOU