Forums › Adobe After Effects Expressions › How to Assign Effects to Duplicated Layers Automatically
How to Assign Effects to Duplicated Layers Automatically
Andac Oktay
November 27, 2019 at 9:44 amHello,
I have trouble with the following expression idea. I would like to achieve this;
I have a Shape Layer named as “Bar 1” and an Adjustment Layer named as “Controller” for control the Y Scale of that position. I wrote this expression to control Y Scale;
ySize = thisComp.layer(“Controller”).effect(“Bar 1”)(“Slider”);
[100, ySize]Everything is ok now. But what i want is; when i duplicate the “Bar 1” Layer there will be “Bar 2”. This new layer should assign it’s Y Scale to the next Slider controller in the Controller layer. In the Controller layer i created lots of Slider Control.
I think maybe i can use something like “Index + 1” but i could not achieve that.
Thank you!
ySize = thisComp.layer("Controller").effect("Bar 1")("Slider");
[100, ySize]Dan Ebberts
November 27, 2019 at 1:35 pmI haven’t tested this, but it is basically how you could extract the number from you layer’s name and use it to build the name of the slider:
myNum = parseInt(thisLayer.name.split(” “)[1],10);
ySize = thisComp.layer(“Controller”).effect(“Bar ” + myNum)(“Slider”);
[100, ySize]Dan
Andac Oktay
November 27, 2019 at 3:33 pmHi Dan!
Thank you, this expression works like a charm. Any time i duplicate the “Bar” layer the new layer takes the new sliders name and assings automatically. So that’s perfect!
Dan Ebberts
November 27, 2019 at 3:42 pmGlad to hear it. I think I actually made it a little more complicated than it needs to be. This should work as well:
myNum = thisLayer.name.split(” “)[1];
ySize = thisComp.layer(“Controller”).effect(“Bar ” + myNum)(“Slider”);
[100, ySize]Dan
Andac Oktay
November 27, 2019 at 4:00 pmYes this is working, too.
I also applied this piece of expression into the “Color Control” effect and it works, too.
You are the best and thanks!
Log in to reply.