Skip to main content
jory22086941x0a7
Inspiring
December 5, 2021
Question

It's there any script API I can get each word position?

  • December 5, 2021
  • 4 replies
  • 746 views

I have a TextLayer with the text "Hello world, It's great".

It's there any script API I can get each word position?

This topic has been closed for replies.

4 replies

Inspiring
December 13, 2021

You can do this using text animators and expressions, plus a little time-based trickery.

 

Add a Character Value text animator to your text with a Range Selector. Set "Start" to -1, "End" to 0, and on the "Offset" property apply the following expression:

 

 

-Math.ceil(time)

 

 

Under the "Advanced" property group, set "Units" to "Index", "Based On" to "Words", "Mode" to "Subtract". Set the "Character Value" property to 32 (which is the space character) and also apply this expression to the "Character Value" property:

 

 

if(time >= 0) 0
else value

 

 

 Once you have set all this up, what you will get is a text layer that displays normally for times greater than or equal to 0 seconds, but that will only display individual words at negative times (it blanks out everything but the word at time = -index). Now if you call sourceRectAtTime(-1) you will get the source rectangle of the first word. -2 will give you the second word, and so on.

 

This can also work for lines, just change "Based On" to "Lines" and then you can access each line's source rect at the time corresponding to its negative index.

jory22086941x0a7
Inspiring
December 14, 2021

It can really run, and it is very precise, thank you so much~~~~~~

Mathias Moehl
Community Expert
December 6, 2021

If you want to split a text via scripting, note that my script TextEploder also comes with its own scripting API such that you ca remote-execute it with other scripts.

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
jory22086941x0a7
Inspiring
December 13, 2021

Great, Thankyou

Inspiring
December 5, 2021

Unfortunately not. I think the best you can do is use sourceRectAtTime() and keep semding different things through a text layer, measuring the size of all the text, the size of a single line of text, and the size of each word then figuring it out from that. Not ideal but certainly possible.

jory22086941x0a7
Inspiring
December 6, 2021

I thought of a way to create two Texts, one to display all, and the other to display only the portion of the all words....and use the sourceRectAtTime API to get the width.....and  compare the two position and width , you can get the word position easily

Mylenium
Brainiac
December 5, 2021

Not sure what you are asking. You simply use the normal AVLayer properties as laid out in the scripting guides. I suggest you look up this stuff.

 

https://ae-scripting.docsforadobe.dev/

 

Mylenium

jory22086941x0a7
Inspiring
December 6, 2021

great, This document help me alot~~~