Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Assign a colorcode to a Color property basing on the compName

  • Assign a colorcode to a Color property basing on the compName

    Posted by Sashank Kondepudi on January 8, 2023 at 3:39 pm

    Hello, I want to assign a color to Fill effect based on the compName. Let’s say I have 3 colors: Black (#000000), White (#FFFFFF) and Grey (#808080) and I want to apply each color for every third comp.

    My comps are named like this – “1. First Comp” “2. Second Comp” “3. Third Comp” and so on…

    Currently I wrote an expression like this for the “Color” property of the Fill effect:

    var n = thisComp.name.split(".")[0];
    
    if(n%3 == 0)
    {
    	FFFFFF;
    }
    else if(n%3 == 1)
    {
    	000000;
    }
    else if(n%3 == 2)
    {
    	808080;
    }

    But this expression is throwing an error. Any help is really appreciated…

    Sashank Kondepudi replied 3 years, 4 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    January 8, 2023 at 3:57 pm

    The colors need to be floating point values between 0 and 1. I’d do it like this:

    n = parseInt(thisComp.name)%3;
    if (n == 0)
    [1,1,1,1]
    else if (n == 1)
    [0,0,0,1]
    else
    [.5,.5,.5,1];
  • Sashank Kondepudi

    January 8, 2023 at 7:24 pm

    Thank you so much, Dan!

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy