Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Reference a layer with index

Community Beginner ,
Mar 13, 2020 Mar 13, 2020

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. 


  1. //TextLayer.transform.Anchor point
    s=thisLayer;
    a=s.sourceRectAtTime(time-s.inPoint);
  2. Height=s.sourceRectAtTime(outPoint).height;
    Width=s.sourceRectAtTime(time-s.inPoint).width;
  3. Top=s.sourceRectAtTime(outPoint).top;
    Left=s.sourceRectAtTime(time-s.inPoint).left;
  4. 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]

TOPICS
Expressions , How to
20.7K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Mentor , Mar 13, 2020 Mar 13, 2020

"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

...
Translate
Mentor ,
Mar 13, 2020 Mar 13, 2020

"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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 13, 2020 Mar 13, 2020
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines