Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Single script to control multiple properties

  • Single script to control multiple properties

    Posted by Touko Maksimainen on August 31, 2009 at 6:01 am

    Hello everyone.

    I’ve got a swarm of layers that need to be positioned and rotation controlled in a specific way. Now I know that I could just make a single layer, put all my expressions in relevant properties and then duplicate it as required. The real problem though is that if I have to change anything, I need to paste the new script to all layers again, which is doable but shouldn’t there be a more elegant way of doing this?

    I know that an expression can’t control any other property than the one it’s been applied to (why not?), but I think I saw an example somewhere that used external javascript functions to do this. It was something like putting “function={“myfunc”}; to the desired property and then have your script sit somewhere and have it control all properties it has been applied to. Can anyone confirm this?

    Filip Vandueren replied 16 years, 8 months ago 2 Members · 1 Reply
  • 1 Reply
  • Filip Vandueren

    August 31, 2009 at 1:41 pm

    Why not?

    Because an expression is a calculation that is substituted for or added to the keyframes of the property it is applied to.
    Just like you can’t set a keyframe for position that changes the rotation, this applies to an expression.

    About your request, in after effects there are no shared functions or global variables, you can’t declare a function in one expression, and call it somewhere else, which is a shame.

    Workarounds are:
    storing a variable that is needed in several expressions, in a slider, or point-control
    storing a text-string in marker-comments
    storing a text-string in an (invisible) text-layer

    The nice thing about Javascript is that you can take a string, and evaluate that string as if it was actuakl source code in the expression.

    So you could have a text-layer that has as text:

    textlayer: “expressionTxt”

    x=Math.cos(time*2+index)*500;
    value+[x,0]

    (or whatever)

    and then from all your swarm layers have position-expression like this:


    expr=thisComp.layer("expressionTxt").text.sourceText.value; // don't forget the .value at the end !
    eval(expr);

    you can use this to “import” functions too. Just eval() the function first, then add the rest of your code calling that imported function.

    Amazing bonus: you can keyframe the sourcetext value of your expressionTxt layer, so you can in effect keyframe what expression is applied to all your layers.

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