October 8, 2021 at 10:24 am
I’m wanting to create a set up where I can use a rectangular shape layer to underline a word in a block of text, the word being chosen by use of a slider that delineates the index number of the word in the block of text.
Eg. if the slider is set to 3, then the third word is selected to be underlined.
Has anyone created something like this?
What I need to do to the rectangle, in something like pseudocode, is this:
On the position of the rectangle:
s = the value of the slider
px = the x position of the word with the index of (s)
py = the y position of the word with the index of (s)
On the scale value of the rectangle:
s = the value of the slider
w = length of the word with the index of (s) <ideally something skin to the sourceRectAtTime function, only just for the word rather than the whole text layer>
h = 5
Is something like this even possible? It seems you can pull and index number from the words in a block of text, if the expression is applied to an expression property on a text layer, but I can’t work out how to delineate an index number to refer to.
Any help would be greatly appreciated.
October 8, 2021 at 4:56 pm
I’d try using a copy of the text layer with the Minimax effect as a matte for the underline.
Create an underline that goes under all your text, could be a shape layer or solid, it just needs to be a single, separate layer that a track matte can be applied to.
Duplicate your text layer add the Minimax effect and set the radius to a value that will be large enough to encompass the underline.
Add a text animator for opacity to this text layer and set opacity to zero. twirl down the range selector > advanced properties and set ‘based on’ to ‘words’, ‘units’ to ‘index’ and ‘mode’ to ‘subtract’. The set the the start value to 2 and the end to 3 to select the 3rd word.
At this point only that 3rd word should be Minimax’d.
Move the underline layer below the Minimax’d text layer and use that Minimax layer as a track matte for the under line to mask out an underline below just the 3rd word.
You can link the character animator’s start and end values to more easily select the word to be underlined.
I think that will get you close to what you are looking for.
October 8, 2021 at 11:38 pm
Played around with this a little more, and found several issues with my method.
You can fix several of the issues by adding one more animator to the text layer that has Minimax applied to it… add a new animator for character value and set it to 95 (this should be the underscore character for most fonts).
Then in that second animator’s advanced settings, set ‘character alignment’ to center.
You can also set the Minimax ‘direction’ to horizontal.
This seems to produce a better underline. It still has mild issues with words that begin or end in narrow characters like an ‘i’.
October 9, 2021 at 5:59 am
This should also work for multiline texts. I use a line instead of a rectangle, I hope this is not an issue.
1. Create a text.
2. Create a second text with an animator that only shows your word. Make this invisible. Set the previous text as parent. Set anchorpoint to [0,0] if necessary and position to [0,0].
3. Create a shape layer. Parent it to the first layer, set anchor point and position to [0,0]. Add a path to this shape layer, and add this expression to the Path property (to modify how low is the line compared to the word, modify diff value):
L = thisComp.layer(index-1);
R = L.sourceRectAtTime(0,false);
myLeft = R.left;
myWidth = R.width;
myTop = R.top;
myHeight = R.height;
diff = 5;
p1 = [myLeft, myTop+myHeight+diff];
p2 = [myLeft+myWidth, myTop+myHeight+diff];
createPath(points = [p1,p2], inTangents = , outTangents = , isClosed = false)
Here is a project that has all this already built in. The second text takes the text, font, font size and leading from the previous so you don’t have to worry about changing both. To change the underlined wort, change the slider on the main text. The only thing you need to pay attention to is not put any layer between these, because there is an expression using (index-1)
Log in to reply.