Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Select random layers and change some properties

  • Select random layers and change some properties

    Posted by Emiliano Grimaldi on May 26, 2021 at 11:43 am

    Hi all,

    I’m trying to solve this problem.

    I would like to make a template with 10 icons and another one with 100 icons, depending on the percentage chosen on a slider I would like to have that percentage chosen from random icons, having those icons changing colour.

    How would you approach this?

    My approach will be to have a layer with all the grey icons and then a composition with all the coloured icons each on his own layer. Have a script choosing random layers based on a slider percentage and modify the transparency or the colour property, but I need help with the scripting.

    Thank you

    Emiliano Grimaldi replied 4 years, 11 months ago 2 Members · 4 Replies
  • 4 Replies
  • Kevin Camp

    May 26, 2021 at 5:04 pm

    If you want to effect the opacities of the layers, you can try this:

    Create a null, add a slider to it and then parent all the layers that you want to control with that slider to the null (this will make the expression easier). Make sure the layers are directly below the null that they are parented to as the expression will use each layer’s index in relation to the null’s index to control their opacities.

    Now copy/paste this expression into the layer first below the parent:

    n = thisComp.layer("Null 1").effect("Slider Control")("Slider") ;
    id = index - parent.index ;
    if ( Math.ceil(n) >= id ) { 100 } else { 0 }

    If the slider is 0, the layer opacity should be 0. If the slider is 1 or more, then the opacity should be 100.

    If that works, you can now right-click that layer’s opacity property and choose Copy Expression Only. Then select all the other layers to parented to the null and choose edit>paste the expression into all of them at once.

    The slider should now control the opacities of all the layers sequentially — a 1 value should turn on the firs layer below the null, a 2 should turn on the 2nd layer, etc.

    You can also use a similar expression to control a color control to desaturate a layer. There are a variety of effects that can do that, but Tint is pretty simple, so I’ll outline that here, try this:

    Add the Tint effect to the first parented layer parented below the null and disable the opacity expression by clicking the ‘=’ button for the expression. Then add this expression to the Tint Amount property of the Tint effect:

    n = thisComp.layer("Null 1").effect("Slider Control")("Slider") ;
    id = index - parent.index ;
    if ( Math.ceil(n) >= id ) { 0 } else { 100 }

    Now, rather than changing the opacity when the slider changes, the layer should change from black and white to color when the value is equal or grater than the layer’s index relative to the null.

  • Emiliano Grimaldi

    May 27, 2021 at 2:31 pm

    Kevin,

    This is fantastic, it works and you explain each step very clearly.

    Now, if I want those layers to be picked up randomly and not sequentially, what do I need to do?

    Thank you

  • Kevin Camp

    May 27, 2021 at 5:47 pm

    Truly random will be tough… you can ask in the expressions forum, but I can’t think of a way to have the opacities or color be both random and follow a rule to use an accurate percentage.

    The only way I can think of would be to use the slider as described above, but then modify the layer order manually to make them random. If you needed the order to change from one usage to another, you could set up several comps and vary the layer orders, then use a slider to control which comp is visible.

    I might be able to come up with another solution, but I’d need to know more about how your icons are arranged.

  • Emiliano Grimaldi

    May 28, 2021 at 3:43 pm

    Hi Kevin,

    One layout could be something similar to this:

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