Skip to main content
Michael MTT
Known Participant
May 16, 2014
Answered

Retrieve Position of last Character of Textlayer

  • May 16, 2014
  • 2 replies
  • 1577 views

Dear Script Experts!

I wonder if there is a way to get position properties of the last character within a text layer.
For example I used this in ActionScript: txt.getCharBoundaries(txt.length - 1);

Thanks for any Help

Mike

This topic has been closed for replies.
Correct answer David Torno

The properties available for a text layer are:

applyFill

applyStroke

boxText

boxTextSize

fillColor

font

fontSize

justification

pointText

strokeColor

strokeOverFill

strokeWidth

text

tracking

Last I saw, per character data retrieval was still not available. Even in AE CC. All text layer property retrieval is based on the first character of the text string. So if each character used a different font, point size, kerning, etc... only the first character's values could be retrieved.

Re: Is there a way to access per-character text properties via script?

Some other posts here that talk about text layer's location:

ADBE Text Document boxTextSize attribute

Getting a box text anchor point after resizing it

You can always request it too.

Adobe - Feature Request/Bug Report Form

2 replies

Inspiring
May 20, 2014

Any solution for this will be a bit of a hack as there's no in built method for it.

You may be able to get somewhere using the AV Layer sourceRectAtTime() method. I've used this approach in the past. It won't work so well if the text layer contains multiple text styles though.

Basically, you find the extents [top, left, width, height] of the whole text layer, then temporarily change it to just the last character (or use a dupe of the layer) and find the new extents. From this you can accurately work out the left and right values.

i.e. right = (fullExtents.left + fullExtents.width);

left = right - lastExtents.width;

Top and bottom is a bit tricker as the last character height might not match the full layers height because of ascenders/descenders, so you may also need to do things like test the extents with examples of each to figure it out.

Another possible solution is to use the sampleImage() expression, applied by a script that also reads the resulting values, after applying a text animator to set Opacity to 0% on all but the last character. It can be slow and laborious but you could sample multiple pixels (preferably using well optimised logic to minimize the number of samples required) until you find the bounds from the pixel alpha values.

Michael MTT
Known Participant
May 21, 2014

Hi Paul, for these advanced hack suggestions! Problem with the first one ist, it won't work for multiline text, since last char in second line can be further to the left.

Anyway thanks a lot for your answers!

Inspiring
May 21, 2014

Well you could do an additional extents test with just the last line of the text to find that line's right extent:

if (theText.indexOf("\r") != -1) {

     textLinesArray = theTest.split("\r");

     lastLineText = textLinesArray[textLinesArray.length-1];

}

David TornoCorrect answer
Legend
May 20, 2014

The properties available for a text layer are:

applyFill

applyStroke

boxText

boxTextSize

fillColor

font

fontSize

justification

pointText

strokeColor

strokeOverFill

strokeWidth

text

tracking

Last I saw, per character data retrieval was still not available. Even in AE CC. All text layer property retrieval is based on the first character of the text string. So if each character used a different font, point size, kerning, etc... only the first character's values could be retrieved.

Re: Is there a way to access per-character text properties via script?

Some other posts here that talk about text layer's location:

ADBE Text Document boxTextSize attribute

Getting a box text anchor point after resizing it

You can always request it too.

Adobe - Feature Request/Bug Report Form

Michael MTT
Known Participant
May 20, 2014

Thanks David for the detailed reply!
Sad truth, but I feared something like this after I did some reverse engeneering on the "decompose text to layer script". They are just using invisible characters to maintain position at the new layers.
I'll think about FR.

Edit: Adding Pic which shows characters anchorpoints for making the topic clearer. We want that data of the anchorpoints!