Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity › Forums › Adobe After Effects Expressions › Editing Source Text to remove a portion of the text

  • Editing Source Text to remove a portion of the text

    Posted by Jacob Thorup on October 23, 2019 at 11:11 pm

    I’m trying to remove a timestamp from a text layer for a script I’m working on.

    I can replace the text completely and I can add more text to the string, but I am having trouble finding the tools to remove certain parts of the text.

    Here is the imported text. I’m trying to remove everything before the second line.

    “John Doe – 4:01PM October 21st, 2019:
    And Here”

    any help or a link to a tutorial would be greatly appreciated! I feel like it might be a real fundamental javaScript thing that I’m just not aware of.

    Jacob Thorup replied 6 years, 11 months ago 2 Members · 7 Replies
  • 7 Replies
  • Dan Ebberts

    October 24, 2019 at 6:18 am

    >I’m trying to remove everything before the second line.

    If that’s really what you’re trying to do, you could do it with this:

    value.split(“\r”)[1]

    but if what you’re after is the name from the first line and what’s in the second line, it would be more like :

    s = value.split(“\r”);
    idx = s[0].search(/\d/);
    s[0] = s[0].substr(0,idx-3);
    s.join(“\r”)

    Dan

  • Jacob Thorup

    October 24, 2019 at 2:15 pm

    First of all:
    This works Perfect!

    Second:
    I was actually wanting to know how to do this in a script, but I forgot to mention that in my post/question. My apologies.

    Is there a way to do this within a script as well?

    Thanks again!

  • Dan Ebberts

    October 24, 2019 at 4:47 pm

    >This works Perfect!

    Which one?

    >Is there a way to do this within a script as well?

    Sure–it’s mostly just JavaScript. If you’re talking about the second one, it would be something like this:

    var s = yourText.split(“\r”);
    var idx = s[0].search(/\d/);
    s[0] = s[0].substr(0,idx-3);
    var newText = s.join(“\r”);

    Dan

  • Jacob Thorup

    October 24, 2019 at 5:15 pm

    The first solution worked great as an expression, but when I try to implement it into my script it doesn’t seem to understand the “split” function.

    Here is the for Loop I’m using it in. “txt” is a global variable for layer 4 in my comp.

    for (var i = 1; i != numberOfSourceText + 1; i++){

    if (txt.property("Source Text").keyValue(i)){

    (txt.property("Source Text").keyValue(i).split("\r"))

    }
    }

    It kicks back the error “Function txt.propert().keyValue().split is undefined.”

    Do I need to import that functionality at the start of my script or something?

  • Dan Ebberts

    October 24, 2019 at 5:35 pm

    I think the issue is that

    txt.property(“Source Text”).keyValue(i)

    is going to give you a text document object, not the text itself.

    This should work though:

    txt.property(“Source Text”).keyValue(i).text.split(“\r”)[1];

    Dan

  • Dan Ebberts

    October 24, 2019 at 5:36 pm

    I just remembered that in scripting, you may have to use .split(“\n”) instead of .split(“\r”)

    Dan

  • Jacob Thorup

    October 28, 2019 at 2:06 pm

    Thanks for the help on this one!

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