ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Editing Source Text to remove a portion of the text

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Jacob Thorup
Editing Source Text to remove a portion of the text
on Oct 23, 2019 at 11:11:40 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.


Return to posts index

Dan Ebberts
Re: Editing Source Text to remove a portion of the text
on Oct 24, 2019 at 6:18:12 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



Return to posts index

Jacob Thorup
Re: Editing Source Text to remove a portion of the text
on Oct 24, 2019 at 2:15:26 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!


Return to posts index


Dan Ebberts
Re: Editing Source Text to remove a portion of the text
on Oct 24, 2019 at 4:47:07 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



Return to posts index

Jacob Thorup
Re: Editing Source Text to remove a portion of the text
on Oct 24, 2019 at 5:15:10 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?


Return to posts index

Dan Ebberts
Re: Editing Source Text to remove a portion of the text
on Oct 24, 2019 at 5:35:01 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



Return to posts index


Dan Ebberts
Re: Editing Source Text to remove a portion of the text
on Oct 24, 2019 at 5:36:41 pm

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

Dan



Return to posts index

Jacob Thorup
Re: Editing Source Text to remove a portion of the text
on Oct 28, 2019 at 2:06:53 pm

Thanks for the help on this one!


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 CreativeCOW.net All Rights Reserved
[TOP]