ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Is it possible to combine two properties from textSource into new text layer?

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Paul Beckett
Is it possible to combine two properties from textSource into new text layer?
on Mar 2, 2020 at 3:03:29 pm

Hi smart people of Creative Cow…

I have been playing around with the new font style expressions now available in Ae cc2020. Now it might be my terminology which is letting me down or my super tired dad brain but I am finding it hard to find clear information on how to combine two properties from a single textSource property from a user text layer into a textSource on another text layer.

What I would like to achieve is to get the width of a single specific character from a string entered by the user on a text layer, I also need to parse the style of the font using the new style or getStyleAt() expression, so the single specific character dynamically changes with any change made to the user input text and an change made to the font style itself. This is so that I can eventually apply an effect to that specific character which is based on the width of that character.

Example:

I want to isolate the “X” from the word “TEXT” and apply an effect based on the width of the “X” to that character.

I can do this using:

a = thisComp.layer("User Text").text.sourceText.charAt(2);

Which gives me just the “X” and a bounding rectangle the size of the “X”.

I also want to parse the style of the font in the user text layer by using:

b = thisComp.layer("User Text").text.sourceText.getStyleAt(0);

On it’s own this expression will parse the font style okay. However I need to combine the two expressions (a and b). Sadly every combination I try either results in an error or no error but no text is not displayed, just a blank text layer.

How would I combine these two, if possible?

a = thisComp.layer("User Text").text.sourceText.charAt(2);
b = thisComp.layer("User Text").text.sourceText.getStyleAt(0);

Normally this isn’t an issue, with for example, numbers as it is just a case of math, but with textSource I’m a little bit lost….

Many thanks!

P.

a = thisComp.layer("User Text").text.sourceText.charAt(2);
b = thisComp.layer("User Text").text.sourceText.getStyleAt(0);

//a.b?
//a + b?


Return to posts index

Alex Printz
Re: Is it possible to combine two properties from textSource into new text layer?
on Mar 2, 2020 at 5:18:04 pm

It looks like defining the style has to be first, and then the actual content is a subset of the style. I'm going to dig a bit more into this, haven't looked much at the new style expressions much, and there's hardly any documentation.

a = thisComp.layer("User Text").text.sourceText.charAt(2);
b = thisComp.layer("User Text").text.sourceText.getStyleAt(0);

style = b;
style.setText(a);

OR

thisComp.layer("User Text").text.sourceText.getStyleAt(0).setText(thisComp.layer("User Text").text.sourceText.charAt(2));


Alex Printz
Mograph Designer


Return to posts index

Paul Beckett
Re: Is it possible to combine two properties from textSource into new text layer?
on Mar 3, 2020 at 8:41:18 pm

Hi Alex,

That did it! Thanks so much for taking the time to help out!

P.


Return to posts index


Patrick Grossien
Re: Is it possible to combine two properties from textSource into new text layer?
on Mar 5, 2020 at 5:58:26 pm

Hey Paul & Alex,

I am trying to access the line spacing via getStyleAt.
But I always keep getting the error that getStyleAt is not a function.

thisComp.layer("TextLayer").text.sourceText.charAt(2)

for example works fine, but

thisComp.layer("TextLayer").text.sourceText.getStyleAt(2)

returns the error.

I tried to debug by putting the code into a sourceText of a second layer, so I can get a visual of the returned data. So far no luck.

I'm working with 17.0.4 CC.

Any hints on how to make use of these new expressions?

Thanks a ton!
Patrick

thisComp.layer("TextLayer").text.sourceText.getStyleAt(2)


Return to posts index

Alex Printz
Re: Is it possible to combine two properties from textSource into new text layer?
on Mar 5, 2020 at 6:08:34 pm

Make sure you're using the newer Javascript expression engine, not extendScript. Style attributes are only available there.

Alex Printz
Mograph Designer


Return to posts index

Patrick Grossien
Re: Is it possible to combine two properties from textSource into new text layer?
on Mar 5, 2020 at 6:19:26 pm

Oh man, thanks a ton! I guess I missed the memo on that! 😉

Patrick


Return to posts index


Alex Printz
Re: Is it possible to combine two properties from textSource into new text layer?
on Mar 5, 2020 at 6:31:34 pm

I don't think extendScript is being updated; Javascript is the new engine that everything will be developed in moving forward.

Alex Printz
Mograph Designer


Return to posts index

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