Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Anchor Point based on the character index

  • Anchor Point based on the character index

  • Tommi Rahko

    September 12, 2020 at 4:15 pm

    Hello peeps.

    Is it possible to assign anchor point of layer based on the index of the character? For instance, if i have text layer with the word “character” and i want the anchor point to be in the center of the second letter how could that be done?

  • Brendon Murphy

    September 12, 2020 at 8:59 pm

    There may be a more elegant solution, but this will get you there:

    textWidth = thisLayer.sourceRectAtTime().width;

    numLetters = thisLayer.text.sourceText.length;

    characterWidth = textWidth/numLetters;

    charIndex = 2;//this is the index of the letter you want

    horizAnchor = (value[0])+(characterWidth*charIndex)-(characterWidth*.5);

    verticalAnchor = value[1];

    [horizAnchor,verticalAnchor];

  • Brendon Murphy

    September 12, 2020 at 9:08 pm

    Note that the above expression is for changing the text’s anchor point to the second character. If you want to change the anchor point of another layer to be at the second character, it’s like this:

    textLayer = thisComp.layer(“CHARACTER”);

    textWidth = textLayer.sourceRectAtTime().width;

    numLetters = textLayer.text.sourceText.length;

    characterWidth = textWidth/numLetters;

    charIndex = 2;

    horizAnchor = (textLayer.transform.position[0]-textLayer.transform.anchorPoint[0])+(characterWidth*charIndex)-(characterWidth*.5);

    verticalAnchor = textLayer.transform.position[1]-textLayer.transform.anchorPoint[1];

    [horizAnchor,verticalAnchor];

  • Tommi Rahko

    September 12, 2020 at 9:42 pm

    Thanks a bunch. Seems to work great 🙂

Viewing 1 - 4 of 4 posts

Log in to reply.

We use anonymous cookies to give you the best experience we can. Our Privacy policy | GDPR Policy