Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions technique: using a text-layer to store an object

  • technique: using a text-layer to store an object

    Posted by Filip Vandueren on February 7, 2009 at 10:27 pm

    Hey Guys,

    I just tried something wacky in another thread, and it works.

    Using an expression on a text-layer to create a string-representation of an object.
    Then eval() that string in other expressions.

    I did it to have some global calculations done it that text-expression, and to pass along more than 1 variable at a time.

    Thought some more about it, and you can even include global functions or prototypes that way. Has this been done before and have I missed it ?

    quick check:
    paste this in a text-layer “txt”.

    function quadruple(i) {return i*4}
    function triple(i) {return i*3}
    obj={a:1, quadruple:quadruple,triple: triple ,c:5}

    use this in an expression:
    eval(thisComp.layer(“txt”).text.sourceText.value);
    quadruple(3);

    returns 12 !

    your thoughts ?

    Jamie Bradshaw replied 13 years, 6 months ago 3 Members · 8 Replies
  • 8 Replies
  • Dan Ebberts

    February 7, 2009 at 11:11 pm

    Filip,

    That’s pretty cool. I’ve used text expressions to “publish” numerous values that all had to be calulated with the same random seed (like shuffling a deck of cards), but I’ve always done it as text, so each of the receiving expressions has to parse the text. Your way is much better I think.

    Dan

  • Filip Vandueren

    February 8, 2009 at 7:11 am

    It’s worth mentioning that the .value after sourceText is mandatory because otherwise the expression tries to eval a textProperty object instead of the string contained by it.
    (this is left out by the pickwhip)
    Usually both are the same because of javascript’s autocasting, but here we have to specifically get the ‘value’

  • Jamie Bradshaw

    October 31, 2012 at 4:47 pm

    Hi Filip and Dan.

    I’m trying to use this technique but I get an error with the eval expression saying “Expected: ]”

    Is there anything in CS6 that would mean that this technique would require tweaking?

    Cheers,
    Jamie

    JimJam•Graphics
    https://www.jimjamgraphics.com/

  • Dan Ebberts

    October 31, 2012 at 5:25 pm

    Try surrounding the sourceText expression with triple quotes.

    “””function quadruple(i) {return i*4}
    function triple(i) {return i*3}
    obj={a:1, quadruple:quadruple,triple: triple ,c:5}”””

    Dan

  • Jamie Bradshaw

    October 31, 2012 at 5:27 pm

    That works, thanks Dan.

    What do the triple quotations do?

    JimJam•Graphics
    https://www.jimjamgraphics.com/

  • Dan Ebberts

    October 31, 2012 at 5:28 pm

    It works for me as-is if you paste the functions and object in as text for the text layer. Or, you can surround the text with triple quotes and paste it in as a sourceText expression.

    Dan

  • Dan Ebberts

    October 31, 2012 at 5:32 pm

    Triple quotes convert everything between them into a single character string (carriage returns included).

    Dan

  • Jamie Bradshaw

    October 31, 2012 at 5:53 pm

    Thanks again Dan. I think I’ve got my head around it all now.

    I think this technique could end up being a bit of a revelation for how I work in After Effects.

    JimJam•Graphics
    https://www.jimjamgraphics.com/

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