Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Help on Scripts

  • Posted by Fernando Gutierrez on April 10, 2008 at 5:06 pm

    Hey All, here is what I need.

    1 – Random SCALE
    a script that sets to the selected layers a random scale number defined on a range. BUT X and Y must be the same.
    I got this, but X and Y are differents values:

    var set_X = [10,15];
    var set_Y = [10,15];

    var myComp = app.project.activeItem;
    var selectedLayers = myComp.selectedLayers;

    for (var i = 0; i < selectedLayers.length; i++) { var myLayer = selectedLayers[i]; var x = 0; var y = 0; x = Math.random() * (set_X[1]-set_X[0]); y = Math.random() * (set_Y[1]-set_Y[0]); myLayer.property("Scale").setValue([x,y]); } CAN ANYONE FIX THAT FOR ME? 2 - Random Change Position a Bit i want a script that get the selected layers position at the current time and change de position X and Y on a random way, pre-defined by a range.. just like the scale i did, but it needs to get the value of the position from the layer.. this one, I got no clues... thx

    Filip Vandueren replied 18 years, 1 month ago 3 Members · 3 Replies
  • 3 Replies
  • Ben Jaffe

    April 10, 2008 at 5:39 pm

    To preface, I’m also new to expressions, but I think I can help, so here it goes:

    1 – why not get a random value for x, then set y to x’s value? That way you’d get a random value for x and y, but they would be linked. ex:
    x = Math.random() * (set_X[1]-set_X[0]);
    y = x;

    2 – to get the position of the layer that the expression is in, use transform.position – you can use the pickwhip for the expression to get any other layer. I assume the wiggler is not an option right? With the wiggler, it won’t be able to wander off, but maybe that’s what you want.

  • Fernando Gutierrez

    April 10, 2008 at 6:06 pm

    Well, actually wiggler is not an option… because i would need to do it layer by layer…
    I got this comp with about 800 layers..
    they are all lined up making some rows, but kinda rotated.. filling an image that will be full screen later..
    what I need now, is a script (not expression) to mess up the layers a bit… to loose this row aspect.. and i just dont want to move just a bit each layer…
    thats why i thought a script would be the way..
    my layers are all 2D seeds. (cotton, rice, etc.)

    This comp is not animated yet…
    im going for layout aproval, then i will animate it…

    got it?

    Thanks by the way

  • Filip Vandueren

    April 11, 2008 at 1:46 pm

    The second script should be something like this:

    var set_X = [-10,10];
    var set_Y = [-10,10];

    var myComp = app.project.activeItem;
    var selectedLayers = myComp.selectedLayers;

    for (var i = 0; i < selectedLayers.length; i++) { var myLayer = selectedLayers[i]; var x = myLayer.property("Position").value[0]; var y = myLayer.property("Position").value[1]; x += set_X[1] + Math.random() * (set_X[0]-set_X[1]); y += set_Y[1] + Math.random() * (set_Y[0]-set_Y[1]); myLayer.property("Position").setValue([x,y]); }

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