Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Is there a way to store expressions in separate layers? Like named functions?

  • Is there a way to store expressions in separate layers? Like named functions?

    Posted by Thomas Ginelli on January 4, 2012 at 12:40 pm

    Hello!

    I’m fairly new to expressions in AE, I did some scripting in 3ds max though so I have some idea about how it works.

    I recently had to apply an expression to over 100 layers. It was a value for the “posterize time” filter that used “seedRandom(index,true)” to differentiate between layers. And later (suprise!) I had to make some changes in these expressions;).

    So the question is: can I “store”(name?) an expression in say, a null layer, and then “link”(call?) values in many layers to the “parent” expression, while retaining layer-specific things like “seedRandom(index)”? So that I could only edit that single “parent” expression when needed?

    If not, is there a way to search all/selected layers for strings of text with a replace option?

    I sure know that you can copy and paste, I also found the topic with the “copy expression only” suggestion that helped a lot, but still these are not fast solutions.

    Thomas Ginelli replied 14 years, 4 months ago 2 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    January 4, 2012 at 2:19 pm

    The closest you can come to calling another expression would be to put the expression in a text layer and use JavaScript’s eval() function to execute it from other expressions.

    I think I disagree with your characterization of Copy Expression Only as not being fast. I use it all the time and find it be a very fast and convenient way to globally update expressions. That being said, it is certainly possible to come up with a script to let you edit the expressions in all/selected layers (there may already be one).

    Dan

  • Thomas Ginelli

    January 4, 2012 at 3:09 pm

    Indeed Copy Expression Only is a viable option, however not as automated as I’d like.

    Your suggestion about using a text layer and JS eval() is most interesting, however I’m not sure how that should work. I tried making a text layer with a simple “i=15;” statement in it and then tried to evaluate it from another layer’s rotate property:

    eval(thisComp.layer(“SCRIPT_LAYER”).text.sourceText)

    and AE says that “a Number, Array or Property is needed” while it gets TextProperty instead.

    Can you tell me how the line of code should look like?

    Regards,
    Thomas

  • Dan Ebberts

    January 4, 2012 at 3:39 pm

    Try it this way:

    eval(thisComp.layer(“SCRIPT_LAYER”).text.sourceText.value)

    Dan

  • Thomas Ginelli

    January 4, 2012 at 3:56 pm

    This worked! Even layer-specific stuff like seedRandom(index) is working as expected!

    Thank you Dan!

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