Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Returning the same text from an old layer, on a new layer, minus the final line

  • Returning the same text from an old layer, on a new layer, minus the final line

  • Tim Johnson

    February 26, 2020 at 6:05 pm

    Hi!

    I’m fairly new to expressions and I’m not exactly sure how to proceed with this.

    I’d like my new text layer to contain the exact same text as another layer in the same comp, but without the last line.

    Here is the error message:

    Object of type TextProperty found where Number, Array or Property is needed

    I was under the impression that tex.split() turns text into an array? Maybe I’m mistaken.

    Any help is much appreciated 🙂

    s = thisComp.layer("Same text, But without The final line"); //original layer
    o = thisLayer // new layer
    sourceTxt = s.text.sourceText; // original text
    newTxt = o.text.sourceText; // new text
    lineSplitTxt = sourceTxt.split("\r"); // splits the original text by line
    lastLine = lineSplitTxt[lineSplitTxt.length-1]; // returns the last line of original text

    newTxt = sourceTxt -= lastLine // I want new text layer to be same as original WITHOUT the last line

  • Dan Ebberts

    February 26, 2020 at 7:18 pm

    This should work:


    inText = thisComp.layer("Same text, But without The final line").text.sourceText;
    splitText = inText.split("\r");
    outText = "";
    for (i = 0; i < splitText.length-1;i++){
    outText += (i == 0 ? "" : "\r") + splitText[i];
    }
    outText

    Dan

  • Andrei Popa

    February 27, 2020 at 7:43 am

    Sholdn’t this be faster and easier?

    sourceText= thisComp.layer("Same text, But without The final line").text.sourceText;
    sourceText.split("\r").slice(0,-1).join("\r")

    Andrei
    My Envato portfolio.

Viewing 1 - 3 of 3 posts

Log in to reply.

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