Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Can’t get Source Text parameter to execute 2 expressions.

  • Can’t get Source Text parameter to execute 2 expressions.

    Posted by Daniel Annefelt on October 5, 2020 at 7:39 pm

    Hello genius people!

    Running AE 17.1.4 with JavaScript enabled,

    I have two simple expressions on the Source Text parameter.

    The first expression retrieves text input from another layer in a separate Comp.

    ______

    comp(“CHANGE TEXT”).layer(“1 Line Small Text”).text.sourceText

    ______

    The second expression changes between two fonts of the text based on a Expressions Checkbox effect.

    ______

    if (comp(“CHANGE TEXT”).layer(“Layout_Selector”).effect(“Comedy Central”)(“Checkbox”) == 1)

    (text.sourceText.style.setFont(“AmericanTypewriter”))

    else

    (text.sourceText.style.setFont(“Helvetica”))

    ______

    Each expression works like a charm when using one or the other.

    But when combined – which is my goal – it stops retrieving the text from the other layer.

    ______

    comp(“CHANGE TEXT”).layer(“1 Line Small Text”).text.sourceText

    if (comp(“CHANGE TEXT”).layer(“Layout_Selector”).effect(“Comedy Central”)(“Checkbox”) == 1)

    (text.sourceText.style.setFont(“AmericanTypewriter”))

    else

    (text.sourceText.style.setFont(“Helvetica”))

    ______

    Obviously there is some syntax missing that tells the Source Text to do two things

    – get text from another layer and check what font to use based on the checkbox.

    But my merger expressions skills can’t crack this.

    Does anyone have a solution to this or is a current AE cc2020 limitation

    cheers!

    .::D

    Yerko Alarcón replied 5 years, 7 months ago 3 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    October 5, 2020 at 8:04 pm

    This should work:

    txt = comp("CHANGE TEXT").layer("1 Line Small Text").text.sourceText.value;

    cb = comp("CHANGE TEXT").layer("Layout_Selector").effect("Comedy Central")("Checkbox").value;

    myFont = cb ? "AmericanTypewriter" : "Helvetica"

    style.setFont(myFont).setText(txt)

  • Daniel Annefelt

    October 5, 2020 at 8:14 pm

    Haha! Ok, overlord expression master – that worked.

    I kind of see what you did – define two variables and then mash them together.

    But most is gibberish to me.

    What does the “?” do and how does the “:” work to define the two options?

    Regardless – super thanx! You guaranteed me at least another months employment.

    Dinner and drinks on me next time you hit Stockholm!

    .::D

  • Dan Ebberts

    October 5, 2020 at 8:24 pm

    That’s the JavaScript ternary conditional operator. It’s a compact alternative to if/else that I like because you can put it on a single line without having to add curly braces.

  • Daniel Annefelt

    October 5, 2020 at 8:34 pm

    Compact and elegant.

    .::D

  • Yerko Alarcón

    October 6, 2020 at 2:35 am

    Hello, Dan! You can help me my equal, I have seen that you are an expert. This happens to me when I open After Effects.

    Message:

    “Unable to run script on line 1. Expected :)”

    Please help me, thank you very much.

    Greetings Yerko

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