Copy link to clipboard
Copied
Hello everybody,
Hopefully somebody can help me out with this:
There are two text layers in my composition and I have a rectangle that is linked to the size of the text of these layers. This worked quite wel so far, but
if my first text layer has more than one line of text, I need to reposition my second text layer. Therefore I made a slider which controls the vertical position of my second text layer. Now I would like to link the size of the rectangle to the y-position of the second text layer. So that if I lower the second text layer, the rectangle grows with a certain amount. Hopefully I could explain the problem clear enough.
This is my code. Please tell me what I am doing wrong. Thank you so much in advance.
heightTextLayer1 = thisComp.layer("Text Layer 1").sourceRectAtTime().height+300;
positionTextLayer2 = thisComp.layer("SLIDER CONTROL Positie").effect("Slider Position Text Layer 2")("Slider").value;
if (positionTextLayer2 >= 0) {
heightTextLayer2 = thisComp.layer("Text Layer 2").sourceRectAtTime().height+300;}
else if (positionTextLayer2 >= 800) {
heightTextLayer2 = thisComp.layer("Text Layer 2").sourceRectAtTime().height+700;}
else if (positionTextLayer2 >= 900) {
heightTextLayer2 = thisComp.layer("Text Layer 2").sourceRectAtTime().height+800;}
else {positionTextLayer2 = thisComp.layer("Text Layer 2").sourceRectAtTime().height+1000;}
x = 1920
if (heightTextLayer1 > heightTextLayer2) {y = heightTextLayer1} else {y = heightTextLayer2}
[x, y]
Thank you so much for your quick response, but unfortunately it just works with the first section.
I assumed because 800 is also < than 900, so I added "&& positionTextLayer2 >=" and now it is working just fine.
So, thank you so much for pushing me into the right direction.
if (positionTextLayer2 < 800) {
else if (positionTextLayer2 < 900 && positionTextLayer2 >= 800) {
else if(positionTextLayer2 < 1000 && positionTextLayer2 >= 900) {
else{
}
Copy link to clipboard
Copied
It looks like your if/else if stack is set up incorrectly. You'll never get to the last three sections because anything greater than zero will end up in the first section. Like this would be better:
if (positionTextLayer2 < 800) {
else if (positionTextLayer2 < 900) {
else if(positionTextLayer2 < 1000) {
else{
}
Dan
Copy link to clipboard
Copied
Thank you so much for your quick response, but unfortunately it just works with the first section.
I assumed because 800 is also < than 900, so I added "&& positionTextLayer2 >=" and now it is working just fine.
So, thank you so much for pushing me into the right direction.
if (positionTextLayer2 < 800) {
else if (positionTextLayer2 < 900 && positionTextLayer2 >= 800) {
else if(positionTextLayer2 < 1000 && positionTextLayer2 >= 900) {
else{
}