Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Sequential function execution for sourceText property

  • Sequential function execution for sourceText property

    Posted by Cricket Collins on July 8, 2025 at 8:18 pm

    Hi, all.

    I’ve been poking at this one for a while now and would like some help. I’m trying to combine two fairly complicated expressions to connect the sourceText property of a text layer to define and link to a dropdown menu in a control layer for font selection and to a slider on the same layer to allow a limited amount of characters per line (the latter of which I found on here, from Dan Ebberts). I’ve tried a few methods, but here’s where I’m at now:

    font01 = "ProximaNova-Black";
    font02 = "ProximaNovaCond-Black";
    font03 = "ProximaNovaExCn-Black";
    font04 = "ProximaNovaExWd-Black";
    font05 = "ProximaNovaWide-Black";
    font06 = "ProximaSera-Black";
    font07 = "ProximaSoft-Black";
    font08 = "ProximaSoftCond-Black";
    font09 = "ProximaSoftExCn-Black";
    dropMenu = comp("Master").layer("Control").effect("Dropdown Menu Control")("Menu").value-1;
    const fontArray = [font01, font02, font03, font04, font05, font06, font07, font08, font09];
    const iterator = fontArray[dropMenu];
    txt = text.sourceText;
    n = comp("Master").layer("Control").effect("Text Width")("Slider");
    outStr = "";
    newLine = "";
    splt = txt.split(" ");
    function txtp() {
        for (i = 0; i < splt.length; i++) {
            if ((newLine + " " + splt[i]).length > n) {
                if (outStr != "") outStr += "\r";
                outStr += newLine;
                newLine = splt[i];
            }else{
                if (newLine != "") newLine += " ";
                newLine += splt[i];
            }
        }
    if (newLine != "") {
        if (outStr != "") outStr += "\r";
        outStr += newLine;
    }
    outStr;
    }
    text.sourceText.style
        .setFont(iterator)
        .setText(txtp)

    The font selection is working great, but I’m stumbling in two places here:

    • First, for some reason the .setText(txtp) is filling the whole function into the source text, including the word “function” at the beginning all the way through the last }. It’s not executing txtp(), just changing the source text to “function textp() {” etc.
    • Second, I’m aware part of the problem is that the txtp() function doesn’t return a value compatible with the .setText operator, but I’m not sure how to fix this. If I could get it to somehow return the modified text, that would be great.
    Brie Clayton replied 10 months ago 3 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    July 8, 2025 at 9:22 pm

    Try changing the last line to:

    .setText(txtp())
  • Cricket Collins

    July 8, 2025 at 9:52 pm

    That took the function out of the source text, but wiped the source text itself so now the layer is blank…

    Before & after screenshots attached.

    This is also what happens when I change

    [code]

    text.sourceText.style

    .setFont(iterator)

    .setText(txtp())

    to

    txtp()

    in order to only run the function and nothing else, which is what makes me think the function itself may not be returning text. Not sure why, though.

  • Dan Ebberts

    July 8, 2025 at 10:06 pm

    Sorry, I didn’t test it before. This seems to work:

    font01 = "ProximaNova-Black";
    font02 = "ProximaNovaCond-Black";
    font03 = "ProximaNovaExCn-Black";
    font04 = "ProximaNovaExWd-Black";
    font05 = "ProximaNovaWide-Black";
    font06 = "ProximaSera-Black";
    font07 = "ProximaSoft-Black";
    font08 = "ProximaSoftCond-Black";
    font09 = "ProximaSoftExCn-Black";
    dropMenu = comp("Master").layer("Control").effect("Dropdown Menu Control")("Menu").value-1;
    const fontArray = [font01, font02, font03, font04, font05, font06, font07, font08, font09];
    const iterator = fontArray[dropMenu];
    txt = text.sourceText;
    n = comp("Master").layer("Control").effect("Text Width")("Slider");
    outStr = "";
    newLine = "";
    splt = txt.split(" ");
    function txtp() {
    for (i = 0; i < splt.length; i++) {
    if ((newLine + " " + splt[i]).length > n) {
    if (outStr != "") outStr += "\r";
    outStr += newLine;
    newLine = splt[i];
    }else{
    if (newLine != "") newLine += " ";
    newLine += splt[i];
    }
    }
    if (newLine != "") {
    if (outStr != "") outStr += "\r";
    outStr += newLine;
    }
    return outStr;
    }
    text.sourceText.style
    .setFont(iterator)
    .setText(txtp())
  • Cricket Collins

    July 8, 2025 at 10:24 pm

    This worked perfectly! Thanks, I knew I was forgetting something simple.

  • Brie Clayton

    July 9, 2025 at 10:55 am

    Thanks for solving this, Dan!

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