Skip to main content
Known Participant
November 30, 2021
Question

How to reference a layer with a certain checkbox effect ticked

  • November 30, 2021
  • 2 replies
  • 331 views

How would I go about doing this? I need to take position property from a certain layer with a checkbox effect ticked. But how do I reference this layer?

 

This is my current solution, surely there is a better option? It's such an awful work around as I have to have the checkbox effect applied to every layer otherwise after effects gives me the error "missing effect":

i = thisComp.layer(index+1).effect("First Word")("Checkbox");
i2 = thisComp.layer(index+2).effect("First Word")("Checkbox");
i3 = thisComp.layer(index+3).effect("First Word")("Checkbox");
i4 = thisComp.layer(index+4).effect("First Word")("Checkbox");
i5 = thisComp.layer(index+5).effect("First Word")("Checkbox");
i6 = thisComp.layer(index+6).effect("First Word")("Checkbox");
i7 = thisComp.layer(index+7).effect("First Word")("Checkbox");
i8 = thisComp.layer(index+8).effect("First Word")("Checkbox");
i9 = thisComp.layer(index+9).effect("First Word")("Checkbox");
i10 = thisComp.layer(index+10).effect("First Word")("Checkbox");
i11 = thisComp.layer(index+11).effect("First Word")("Checkbox");
i12 = thisComp.layer(index+12).effect("First Word")("Checkbox");
i13 = thisComp.layer(index+13).effect("First Word")("Checkbox");
i14 = thisComp.layer(index+14).effect("First Word")("Checkbox");
if (i == 1 ) {1}
else if (i == 1 ) {1}
else if (i2 == 1 ) {2}
else if (i3 == 1 ) {3}
else if (i4 == 1 ) {4}
else if (i5 == 1 ) {5}
else if (i6 == 1 ) {6}
else if (i7 == 1 ) {7}
else if (i8 == 1 ) {8}
else if (i9 == 1 ) {9}
else if (i10 == 1 ) {10}
else if (i11 == 1 ) {11}
else if (i12 == 1 ) {12}
else if (i13 == 1 ) {13}
else if (i14 == 1 ) {14}
else {0}


 

This topic has been closed for replies.

2 replies

Mylenium
Legend
November 30, 2021

What would such a script do that the normal align functions can't? Seems like you're going out of your way to make a simple thing complicated. Otherwise your code just doesn't make a lot of sense and is highly inefficient. If you really already use a slider, it would be as trivial as something like that to set all the layers to the same X position, assuming their anchor points are correctly aligned:

 

mSlider=thisComp.layer("XYZ").effect("Slider")("Slider");

mRef=index+Math.floor(mSlider);

mPos=thisComp.layer(mRef).transform.position;

 

X=mPos[0];

Y=value[1];

 

Mylenium

Meng Zhiqun
Inspiring
November 30, 2021

Hi Flik,

 

I'm trying to understand your explanation but I don't think I'm getting the full picture. May I check with you if you are trying to link 15 layers to 1 layer? If so, how different are the comps from each other? Would it be possible to create one comp with essential graphics to replace it with the 15 layers? It would be best if you could provide an example too.

Known Participant
November 30, 2021

Hey Meng!

Right, so I'm trying to write a script that will auto align multiple different text layers, so one after the other. See below:

 

At some point, the layers will need to enter a new line. For example, 'Understand' has to be on a new line.

The way I'm setting this up, is by having the a slider with those if/else statements on it, to tell the current layer "the first word in this phrase is # layers below" So for 'Understand' it would be 2.

Meng Zhiqun
Inspiring
November 30, 2021

Probably same as what mylenium has said, I don't understand the requirement of using a slider here for this situation. May I ask why not a carriage return with "/n" or "/r" for this situation?