ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Create shape/box based on word index

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Christian Simpson
Create shape/box based on word index
on Mar 23, 2018 at 8:19:38 pm

Hey everybody I was wondering if there was a way to create a shape behind a piece of text that is based around the word index. My end goal is to try and create a slider control that allows you to simply type in the index number of the word in the paragraph that will have a shape placed behind it. Not sure if that makes sense.

Thanks


Return to posts index

Kevin Camp
Re: Create shape/box based on word index
on Mar 23, 2018 at 9:32:55 pm

there's not an easy way....

you can use sourceRectAtTime() but you have to separate each word on a separate layer... which wouldn't be too bad if the text was on a single line. you'd also need to determine the max number of words, since you'd need that many text layers pre-made.

if you need the text to wrap to new lines, it will get more complicated.

you can easy change the color of an individual word in a text layer with AE's text animators, if that would work...

Kevin Camp
Art Director
KCPQ, KZJO & KRCW


Return to posts index

Christian Simpson
Re: Create shape/box based on word index
on Mar 24, 2018 at 2:37:24 am

Thanks for the reply Kevin, yeah I was afraid it wasn't completely possible.


Return to posts index


Tomas Bumbulevičius
Re: Create shape/box based on word index
on Mar 24, 2018 at 1:16:45 pm

Hey Christian,

could you please elaborate more what you mean by this?

>a shape behind a piece of text that is based around the word index.

1. Do you want to have a solution, where paragraph of text would have a shape behind the particular word of the phrase, and this should move along the text as you skim through the slider?
2. Are you going to make that adjustment of highlight, manually?
3. It needs to work independent from the phrase length?

Thanks!


Return to posts index

Kalleheikki Kannisto
Re: Create shape/box based on word index
on Mar 29, 2018 at 1:27:48 pm

Imposing one limitation makes this (relatively) doable with expressions. The one limitation is that you would need to have manual line breaks at the end of each line of text.

If you started from that, you would then need three additional copies of the text layer where you pulled substrings of the original text (by sourceText expressions):

Copy 1: All text from the beginning up to and including the word to be highlighted
Copy 2: The words between the last manual line break and the word to be highlighted
Copy 3: Just the word to be highlighted

Using those three layers you could then calculate, using SourceRectAtTime, all the necessary coordinates for your highlight box.

Copy 1 would give you the y-position in relation to the top of the textbox.
Copy 2 would give you the x-position in relation the the left edge of the text box and
Copy 3 would give you the width (and height) of the highlight

Not particularly simple, but doable.

Kalleheikki Kannisto
Senior Graphic Designer


Return to posts index

Christian Simpson
Re: Create shape/box based on word index
on Mar 29, 2018 at 3:23:30 pm

To better elaborate what my true end goal to do is I would like a slider that allows an editor to go to the index number needed to highlight the word they want to highlight in a paragraph of text.

So based on the slider the box is created with my desired padding around the word based on index. Not sure if that makes sense.


Return to posts index


Kevin Camp
Re: Create shape/box based on word index
on Mar 30, 2018 at 11:56:35 pm

Kudos to you Kalleheikki, that's pretty ingenious.

Christian, if Kalleheikki doesn't get back to you, I may take a look at this over the weekend... although I have easter eggs to color....

Kevin Camp
Art Director
KCPQ, KZJO & KRCW


Return to posts index

Kalleheikki Kannisto
Re: Create shape/box based on word index
on Apr 2, 2018 at 10:39:49 am

Here's a basic implementation. Somewhat error-prone. You will have to do the line breaks as paragraph breaks without a space character before the line break. There area few other issues, the primary being that with mixed case on some words the highlight goes too low. This is due to the extenders in letters like "j" that push the bottom of the textbox down. You'd be better off changing the y position to be a fixed multiple of the number of lines, which can be done pretty easily. But then you will need to know the line spacing value, so this would require a separate slider.

Also, currently you will have to break the text at the same point where it would reflow automatically in the textbox. This behavior could be changed so that this not a requirement.

AE CC2017 file.

12313_texthighlighting.aep.zip

Kalleheikki Kannisto
Senior Graphic Designer


Return to posts index

Kalleheikki Kannisto
Re: Create shape/box based on word index
on Apr 2, 2018 at 10:45:47 am

Looks like this. Might work as is with all upper case letters.



Kalleheikki Kannisto
Senior Graphic Designer


Return to posts index


Christian Simpson
Re: Create shape/box based on word index
on Apr 2, 2018 at 4:11:24 pm

Wow, this is amazing, it actually works. Brilliant Kalleeikki, thank you very much. Incredible.


Return to posts index

Christian Simpson
Re: Create shape/box based on word index
on Apr 2, 2018 at 5:14:48 pm

One thing I noticed after a while was how changing the font seems to break everything. Do you know why that would be?


Return to posts index

Christian Simpson
Re: Create shape/box based on word index
on Apr 2, 2018 at 5:36:43 pm

Ok I figured it out. I needed to change the text for the hidden text layers as well. Everything needs to match up exactly and that makes sense.


Return to posts index


Kalleheikki Kannisto
Re: Create shape/box based on word index
on Apr 2, 2018 at 6:31:01 pm

Yes, that's correct. The typeface, type size, leading and text box width have to match on all layers in order for this to work. And it is still pretty easy to find ways to break this. For instance, you wouldn't be able to mix typefaces or type sizes, or put line breaks in better places. But if you're careful, it works.

Kalleheikki Kannisto
Senior Graphic Designer


Return to posts index

Dorca Musseb
Re: Create shape/box based on word index
on Aug 22, 2018 at 12:59:12 am

Thanks so much for this file.

Not to add to the complexity of it. Any way to highlight a chunk of the text? Not just one word?

Also... this isn't working with CC2018... :(


Return to posts index

Kalleheikki Kannisto
Re: Create shape/box based on word index
on Aug 22, 2018 at 11:11:47 am

Works fine for me in CC2018. The slider values need to be integers; the expression on the slider should take care of that.

Chunk of text: You can't span two lines with this code. The only thing you can (possibly) do is to use non-breaking spaces between some words so as to force them to highlight together. But they would have to be on the same line, nevertheless.

What would have to happen to be able to highlight a chunk of text on multiple lines is that you'd have have as many copies of this setup as the maximum number of words you needed to highlight, and a sliders to tell the first and the last word. The number of copies of the highlighting code that would be activate at a given moment would depend on the number of words between the first and the last. The existing setup is complex enough for me, so I wouldn't want to try that.

Kalleheikki Kannisto
Senior Graphic Designer


Return to posts index


Jarle Leirpoll
Re: Create shape/box based on word index
on Sep 12, 2018 at 6:54:30 am

FYI: The expressions engine got an update in the 15.1.0 (CC 2018.1.0) version, where support for extents in Paragraph Text was added. In older versions, only shape layers have extents.

For a Paragraph Text layer, including extents will measure the bounding box, instead of only the bounds of the text's visible pixels.

This change created problems for some users who had used "sourceRectAtTime(time, true)" for Paragraph Text in older versions, where the extra code didn't do anything. In newer versions of Premiere Pro, the expressions suddenly behaved very differently, and they had to delete that extra code in their expressions.

Hope this helps.

// Previous expression
text_width = wordLayer.sourceRectAtTime(time, true).width;

// How you need to write it now
text_width = wordLayer.sourceRectAtTime(time, false).width;

or simply

text_width = wordLayer.sourceRectAtTime().width;


Jarle Leirpoll
PremierePro.net


Return to posts index

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