Reference a layer with index
I have a working project that I'm revisiting. It is a simple box (shape layer) that adjusts its position and size to a text layer. I’m thinking about ways to make it more efficient. In the expression I reference the layers by name, which is a hassle if I want to duplicate the layers. What I want is the shape layer to reference the layer above it, i.e. the text layer. But I despite my efforts I can't seem to get it to work. If anyone could please take a look at this, it would be very much appreciated.
//TextLayer.transform.Anchor point
s=thisLayer;
a=s.sourceRectAtTime(time-s.inPoint);- Height=s.sourceRectAtTime(outPoint).height;
Width=s.sourceRectAtTime(time-s.inPoint).width; - Top=s.sourceRectAtTime(outPoint).top;
Left=s.sourceRectAtTime(time-s.inPoint).left; - x=Left+Width/2;
y=Top+Height/2;
[x,y]
//ShapeLayer.transform.Anchor Point;
s=thisComp.layer("Text");
a=s.sourceRectAtTime(time-s.inPoint);
Height=s.sourceRectAtTime(outPoint).height;
Width=s.sourceRectAtTime(time-s.inPoint).width;
Top=s.sourceRectAtTime(outPoint).top;
Left=s.sourceRectAtTime(time-s.inPoint).left;
pCheck=s.sourceRectAtTime(time-s.inPoint).width;
if (pCheck>0){
p=50;
}else{
p=0;
}
x=Width/-2-Left;
y=Height/-2-Top;
[x,y]
//ShapeLayer.contents.Rectangle1.Rectangle Path1.size
s=thisComp.layer("Text");
Height=s.sourceRectAtTime(outPoint).height;
Width=s.sourceRectAtTime(time-s.inPoint).width;
pCheck=s.sourceRectAtTime(time-s.inPoint).width;
if (pCheck>0){
p=50;
}else{
p=0;
}
x=Width+p;
y=Height+p;
[x,y]
