Copy link to clipboard
Copied
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]
1 Correct answer
"index" gives you the index of the current layer. It's the number you see in the timeline in front of the layer. It starts by 1 and goes to as much as layers you have.
To refer to another layer, you can use "index + n" or "index - n" where n is the step you will take.
The layer above is index - 1, the layer beneath is index + 1.
So, basically, if the textlayer is layer 1 and the shape layer with the expression is layer 2, you change this:
s=thisComp.layer("Text");
to this:
s = thisComp.layer(in
...Copy link to clipboard
Copied
"index" gives you the index of the current layer. It's the number you see in the timeline in front of the layer. It starts by 1 and goes to as much as layers you have.
To refer to another layer, you can use "index + n" or "index - n" where n is the step you will take.
The layer above is index - 1, the layer beneath is index + 1.
So, basically, if the textlayer is layer 1 and the shape layer with the expression is layer 2, you change this:
s=thisComp.layer("Text");
to this:
s = thisComp.layer(index-1);
and you are done.
*Martin
Copy link to clipboard
Copied
That is so just what i tried to do...and failed. Must have been a typo because it works like a charm. Thanks for your help.

