Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions For loop that index references the name of a layer skipping layers otherwise

  • For loop that index references the name of a layer skipping layers otherwise

    Posted by Scott Mcgee on March 18, 2017 at 1:29 pm

    So I’ve built a bar graph. This bar graph will be used by staff members who have minimal knowledge of after effects and like boxes that you fill out and hit a button that will automatically make this happen. So I have built my own UI panel that does this with edit boxes that will allow for changes. This is tested and works.

    But the problem is, they don’t always want 5 bars, sometimes they want 3 or 10 for example.

    So what I want it to do. If I duplicate a shape layer (bar), it will change its position to sit next to the next one.

    I’ve seen this tutorial that is pretty much what I want it. I’ve written a script that will update or duplicate the layer. So I don’t need to worry about the array feature.

    https://vimeo.com/57879355

    Only one issue I have with this. That I’m hoping someone my be able to help with.

    var myIndex = effect(“bar_index”)(“Slider”).value;
    var tOrigWidth = (myIndex-1) * thisLayer.source.width *1.1;
    [tOrigWidth, value[1]];

    because I will be putting layers underneath these (Background image and graphical element). This slider control is helpful, but I want it too automatically look at the layer below and change The sliders control value + 1

    This works, but only for the layer directly below.

    thisComp.layer(index+1).effect(“bar_index”)(“Slider”).value + 1;

    I need it to reference the next one in the comp if I decide to place something between the layers. For example.

    1: Controller
    2: Text 4
    3: Text3
    4: Bar 6
    5: Text 2
    6: Bar 5
    7: Bar 4
    8: Bar 3
    9: Bar 2
    10: Bar 1
    11: BKGD

    (So ‘Bar 6’, with the current expression breaks producing an error. I want it to look down the list and find the next one ‘Bar 5’)

    I’ve taken a look at a lot of threads that match name of layer, but I have had no success in finding an expression that works. I know the index will have to be something on the lines of thisComp.Layer(i), using the (i) to index all the layers, but I can’t get it to find the next one.

    I also need too take into account that when I duplicate my layers name is going to change bar1,bar2,bar3.

    findName = “Bar”;
    for (i =index; i <=thisComp.numLayers; ++i) { if (thisComp.layer(i).name.indexOf(findName) != -1) { effect("bar_index")("Slider").value + 1; break; } }

    This works, but it’s now referencing the number of layers. I’m nearly there.

    Any suggestions would be greatful

    Some contents or functionalities here are not available due to your cookie preferences!

    This happens because the functionality/content marked as “Vimeo framework” uses cookies that you choosed to keep disabled. In order to view this content or use this functionality, please enable cookies: click here to open your cookie preferences.

    Scott Mcgee replied 9 years, 5 months ago 1 Member · 1 Reply
  • 1 Reply
  • Scott Mcgee

    March 20, 2017 at 4:59 pm

    Still struggling with this,

    But to update…

    var name = “Bar”;
    for (i =1; i <=thisComp.numLayers; ++i) {
    if(thisComp.layer(i).name){
    i;
    break;
    }
    }

    I thought the expression was referring to the name Bar, but when I deleted this and left it blank. It still worked, which is fine. Except I still have the problem of this

    I want the expression to still +1 my slider, so it shifts the position, but I want it to ignore any layer inbetween so I don’t get the gap.

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