Shadow box around Text subtitles
Hi,
I have been using this expression for while to create a box about my text subtitles. the expression has been apllied to a shape layers size.
x=thisComp.layer(index-1).sourceRectAtTime().width+30;
y=thisComp.layer(index-1).sourceRectAtTime().height+25;
[x,y]
now for this to work I've needed a new shape layer for each new text.
Now I am not a coder and I have been trying to get ChatGPT to help me to modify this exprresson so it will work on multiple text layers instead of just 1. So I will have only 1 shape layer with multiple text layers above it.

I did get a few eamples out of ChatGPT but they still will only work witht he first layer. here are some of the examples.
// Get the dimensions of the previous layer
prevLayer = index - 1;
if (prevLayer < 1) {
// If this is the first layer, set the dimensions to 0
x = 0;
y = 0;
} else {
// Otherwise, get the dimensions of the previous layer
x = thisComp.layer(prevLayer).sourceRectAtTime().width + 30;
y = thisComp.layer(prevLayer).sourceRectAtTime().height + 25;
}
// Return the dimensions as an array
[x, y]
There was this one but there was an error on line 3 as i'm not sure if AE expression can see the sourcetext line.
// Get the dimensions of the previous text layer
prevLayer = index - 1;
if (prevLayer >= 1 && thisComp.layer(prevLayer).sourceText) {
// If this is not the first layer and the previous layer is a text layer, get its dimensions
x = thisComp.layer(prevLayer).sourceRectAtTime().width + 30;
y = thisComp.layer(prevLayer).sourceRectAtTime().height + 25;
} else {
// Otherwise, set the dimensions to 0
x = 0;
y = 0;
}
// Return the dimensions as an array
[x, y]
any help would be great thanks!

