Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions increments for loop

  • increments for loop

  • Scott McGee

    February 13, 2020 at 10:02 am

    Hopefully someone might be able to suggest something.

    I have an array that create buttons, but I want to create a new row for every so many buttons. I’ve looked at resize(), but it’s going over my head. Currently…I manually say for 1-5 create row1, 6-10 create row2

    I want to simplify it in a for loop. I know the below code isn’t right, but hopefully suggests what I want

    for(var i=1, i

    currently it looks like this, but I just want to make it look neater, plus if I add more to the array I don’t have to create a new row every time.

    var b = new Array();
    for(var i = 0; i <= 44; i++ ){
    var f = File (file.name)
    if(i <= 6){
    b[i] = buttonsRow1a.add (“iconbutton”, undefined, f, {style: “toolbutton”});
    }else if(i >= 7 && i <= 13){
    b[i] = buttonsRow1b.add (“iconbutton”, undefined, f, {style: “toolbutton”});
    }else if (i >= 14 && i <= 20){
    b[i] = buttonsRow1c.add (“iconbutton”, undefined, f, {style: “toolbutton”});
    }else if(i >= 21 && i <= 27){
    b[i] = buttonsRow1d.add (“iconbutton”, undefined, f, {style: “toolbutton”});
    }else if(i >= 28 && i <= 34){
    b[i] = buttonsRow1e.add (“iconbutton”, undefined, f, {style: “toolbutton”});
    }else if(i >= 35 && i <= 41){
    b[i] = buttonsRow1f.add (“iconbutton”, undefined, f, {style: “toolbutton”});
    }else{
    b[i] = buttonsRow1g.add (“iconbutton”, undefined, f, {style: “toolbutton”});

    }
    }

  • Scott McGee

    February 13, 2020 at 10:07 am

    don’t know what happened there . Must have caught delete on a portion of the code. This is the kinda thing I want to do

    for(var i=1, i

  • Scott McGee

    February 13, 2020 at 10:09 am

    for(var i=1, i<b.length, i++){
    var j = for every increment of 5, increment by 1 (so if 1-5 = 1. if 6-10 = 2);
    if( i = increments of 5){
    b[i] = row[j].add ("iconbutton", undefined, f, {style: "toolbutton"});
    });
    }

  • Scott McGee

    February 13, 2020 at 10:39 am

    I’m nearly there, but I’m struggling to pass the j

    var b = new Array();
    for(var i = 0; i <= 2; i++ ){
    var f = File (file.name)
    var j = Math.round(i/5)+1;
    b[i] = buttonsRow[j].add ("iconbutton", undefined,f, {style:"toolbutton"});
    }

  • Scott McGee

    February 13, 2020 at 1:51 pm

    This is a bit neater to my original, but I still would rather have it as a few lines, but I can’t get it to work.

    var b = new Array();
    for(var i = 0; i <= 15; i++ ){
    var f = File ("/Volumes/Server/Video/CAPi RenderBot Source/Logos/"+folder1[i].name);
    if(Math.floor([i]/5) == 0){
    b[i] = buttonsRow0.add ("iconbutton", undefined, f, {style: "toolbutton"});
    }else if(Math.floor([i]/5) == 1){
    b[i] = buttonsRow1.add ("iconbutton", undefined, f, {style: "toolbutton"});
    }else if(Math.floor([i]/5) == 2){
    b[i] = buttonsRow2.add ("iconbutton", undefined, f, {style: "toolbutton"});
    }
    }

  • Scott McGee

    February 13, 2020 at 2:40 pm

    That was not fun, but if anyone is building a script to contain multiple rows. Here’s how to do it.

    I can’t be bothered tidying up further as I’ve already shaved 12 lines and it’ll now work for more and more row.

    var b = new Array();
    for(var i = 0; i <= 15; i++ ){
    var f = File (folder1[i].name);
    var str = "buttonsRow" + (Math.floor(i/5));
    var n = eval(str);
    b[i] = n.add ("iconbutton", undefined, f, {style: "toolbutton"});
    }

Viewing 1 - 6 of 6 posts

Log in to reply.

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