Activity › Forums › Adobe After Effects Expressions › Expression based on Layer Color
-
Expression based on Layer Color
Posted by Jon Smith on March 3, 2016 at 11:08 pmIs it possible to have an expression based on the color of a layer? I tried this but it’s doesn’t appear to work. Funny thing is it doesn’t throw an error either.
if (thisLayer.label = 1) {
100;
} else {
0;
}Jon Smith replied 10 years, 2 months ago 2 Members · 4 Replies -
4 Replies
-
David Conklin
March 3, 2016 at 11:31 pmYour expression is evaluating as true because you’re using a single equals sign (assignment.) instead of a double equal sign. If you change your expression to ‘thisLayer.label == 1’ it throws an error saying ‘layer’ has no property ‘label.’
The reason this works is because ‘layer’ is an object, and my saying thisLayer.label = 1 you’re adding a new property to thisLayer. You could also do thisLayer.appple = 1. If you were then to call (thisLayer.apple == 1) you would get a ‘true’ value.
I don’t see any mention of labels in the expression reference, so you may be out of luck. External scripts can access labels, though, so there may be a script oriented solution rather than an expression oriented one.
If you give some more details on the problem you’re trying to solve perhaps we can offer another solution.
David Conklin
Motion Designer -
Jon Smith
March 3, 2016 at 11:43 pmAhhh, that makes sense.
A simplified explanation of what I’m trying to do is… I have a ton of layers that I want to move in several different ways. I was hoping I can select a bunch and label them “blue” and they move one way and select other layers and label then “red” and they move another way. It’s more complicated then just moving but that’s the idea. I can use a check box or something but it just takes a lot longer. Maybe I can do it with markers or something. Any ideas are much appreciated. Thanks!
-
David Conklin
March 4, 2016 at 12:07 amYou can use the name of the layer itself. Just prefix the layers with some descriptor and then a universal character that ‘splits’ the name. For instance:
Grp1/My Layer
Grp1/My other layer
Grp1/My third layer
Grp2/My Layer
Grp2/My other layer
Grp2/My third layer
Grp3/My Layer
Grp3/My other layer
Grp3/My third layerYou can then use thisLayer.name.split(“/”)[0] to get just the “Grp#” part of the name. From there you can apply whatever rules based on the groups name. If you want the part after the slash, you’d do thisLayer.name.split(“/”)[1].
There are some other options here, too, such as using .parseInt(1,10) to extract the “1” from “Grp1” (might freak out if you have other numbers in your layers name). Additionally, you could use .indexOf() or a regex to check which ‘grp’ each layer lives in. Unfortunately I don’t know which of these is optimal in terms of calculation speed. I use .split() because I’m used to it, and you can get both sides of the “/” (as it separates the string into an array).
AE Global Renamer, if you don’t already use it, will speed up this process a ton. I recommend grabbing it. It’s free.
Good luck!
Hope this was helpful. Feel free to follow up if you have any more questions.
David Conklin
Motion Designer
Reply to this Discussion! Login or Sign Up