Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions For loops to create a dynamic array

  • For loops to create a dynamic array

    Posted by Harry Hoag on April 8, 2016 at 10:38 am

    Hiya

    I have a middling knowlege of expressions. The only coding I do is with ae expressions, so please excuse any ignoramus comment i might make! And what I’m trying to do is quite ambitious for my level of code.

    I’ve been working with a js developer here at work to get this expression working. We are trying to create an array that will store all the values between a given number of known points.

    So imagine a spline with multiple points (e.g 4) drawn top to bottom in a comp. Those points have various X positions away from 0. We are then splitting the imaginary spline up into a given number of sub points (e.g 100). We are then trying take those known points and find all the X positions between those points on the spline for each of the sub points. So if there were 4 known points and 100 total sub points there would be 25 sub points between each known point.

    This effectively generates a spline in an array from a given number of x positions. The Y positions of the points are at equal distance from each other for simplicity.

    The following code we believe should work, however with no debug window in AE we are working blind. Is there anyone out there with the knowlege of expressions and js to know if there is a compatibility problem or something?

    For example we are using a for loop within a for loop, is that possible in after effects? Is there anything else which might be a problem here? We thought there might be a problem with ‘push’ to add values to the array, but maybe not. It’s so hard to know where the code is falling down.

    linearSpline = [];
    TOTAL = thisComp.layer("TAPER CONTROLS").effect("Total Subdivisions")("Slider");
    point0 = thisComp.layer("TAPER CONTROLS").effect("1")("Slider");
    point1 = thisComp.layer("TAPER CONTROLS").effect("2")("Slider");
    point2 = thisComp.layer("TAPER CONTROLS").effect("3")("Slider");
    point3 = thisComp.layer("TAPER CONTROLS").effect("4")("Slider");
    pointArray = [point0, point1, point2, point3];

    NUM = parseInt(thisProperty.propertyGroup(3).name.split(" ")[1],10);

    //startW+((endW-startW)*(((100/TOTAL)*NUM)/100))

    var SUB_POINT_COUNT = Math.ceil(TOTAL / pointArray.length);

    var j;

    for (var i = 0; i < pointArray.length; i = i + 1) {

    // Find between values
    if (i === (pointArray.length - 1)) {
    break;
    }

    var difference = Math.abs(pointArray[i] - pointArray[i+1]);
    var subPointValue = Math.round(difference / SUB_POINT_COUNT);
    j = difference;

    for (var v = 0; v < SUB_POINT_COUNT; v++) {
    // linearSpline.push(subPointValue);
    linearSpline[linearSpline.length] = subPointValue;
    }

    }

    linearSpline[NUM]

    I hope that all makes sense, I’d be more than happy to help with more explanation of what we are trying to achieve if anyone can help!

    thanks

    H.

    Miguel De mendoza replied 10 years, 1 month ago 3 Members · 4 Replies
  • 4 Replies
  • Miguel De mendoza

    April 8, 2016 at 12:17 pm

    With expressions you can do most javascript common stuff, but you have to take in acount two things:
    1-Expressions are evaluated each frame
    2-Expressions don’t have memory, that means they can’t reach variables calculated in the frame before, unless the value is the final result of the last calculation, that is stored in the property value.

    So you can nest all the loops you want and make the most complex code in the world, but your computer maybe blows up. You can see expressions like a function, that is calculated each frame, with a return value, wich is the last variable/value you stored in the code, and is asigned to a variable: the property where you are writing the code.

    That said,what exaclty are you trying to achieve (in non programmer words ;)? Where are you writing that expression?

  • Dan Ebberts

    April 8, 2016 at 5:09 pm

    Nested for loops should be fine. Are you getting an error message?

    Dan

  • Harry Hoag

    April 11, 2016 at 10:32 am

    Hey Miguel and Dan, thanks for responding. I have it working now with some more help from a dev friend of mine. I’m trying to make a new tool to expand the capability of shape layers. We’re going to release it as a script hopefully soon.

    The main problem was a few parts of our calculations which were not correct. It was returning the wrong number of array data points which was why I was getting an out of range of array error. But you guys were right about the for loops and compatibility working.

    It’s so hard making stuff like this without a console, no way to debug. I hear there’s a limited way to debug with a text layer? Can you guys recommend the best way to debug?

  • Miguel De mendoza

    April 11, 2016 at 10:57 am

    As far a I know, text layers are the most aproximate to a console you can get :/

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