Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions position expression for a text range selector

  • position expression for a text range selector

    Posted by Randy Davis on February 17, 2011 at 1:22 am

    Let me start off by saying that I am a total neophyte when it comes to expressions and coming from a designers perspective, I have a hard time wrapping my brain around expressions. That said, would I would like to do should be fairly easy to accomplish.
    I have some text with the typewriter effect applied to it, and on another layer I have a cursor graphic. I am trying to link the position of the cursor so that its position is always one character in front of the text as it types on. I want the Y position of the cursor to be the same as the Y of the text. So the X position is the only part of the position that changes.
    I know the range selector returns a value of 0-100, how do I convert that value to a value that translates to the X position? I know this is probably really basic, but any help would be appreciated. Thanks,

    RainMan in Seattle

    Christopher Doulgeris replied 3 years, 4 months ago 4 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    February 17, 2011 at 5:32 am

    I don’t think the range selector percentage gives you an accurate enough position unless maybe if your font is monospaced. The sampleImage() hack should work OK though. Try this:

    L = thisComp.layer(“Your Text Layer”);
    for (i = thisComp.width; i >= 0; i–){
    temp = L.sampleImage([i,thisComp.height/2],[0.5,thisComp.height/2],true,time);
    if (temp[3] > 0) break;
    }
    [i + width/2,L.transform.position[1]]

    Dan

  • Dan Ebberts

    February 17, 2011 at 5:46 am

    This works better when the text isn’t visible yet:


    L = thisComp.layer("Your Text Layer");
    gotIt = false;
    for (i = thisComp.width; i >= 0; i--){
    temp = L.sampleImage([i,thisComp.height/2],[0.5,thisComp.height/2],true,time);
    if (temp[3] > 0){
    gotIt = true;
    break;
    }
    }
    if (gotIt)
    [i + width/2,L.transform.position[1]]
    else
    L.transform.position + [width/2,0]

    Dan

  • Randy Davis

    February 17, 2011 at 9:28 pm

    Thanks Dan,
    that works great. I had to subtract some pixels on the (gotit) and else L.transform.position lines to get the cursor to start and end in the right spots, but after that it works like a charm! Thank you, thank you! that will save me a ton of time not having to keyframe the other four words I need. You my friend are awesome.

    Sincerely,
    Randy D.

    L = thisComp.layer("auto repair shop");
    gotIt = false;
    for (i = thisComp.width; i >= 0; i--){
    temp = L.sampleImage([i,thisComp.height/2],[0.5,thisComp.height/2],true,time);
    if (temp[3] > 0){
    gotIt = true;
    break;
    }
    }
    if (gotIt)
    [i + width/2,L.transform.position[1]]-635;
    else
    L.transform.position + [width/2,0]-660;

  • Alex Dobbin

    July 26, 2011 at 4:19 pm

    Hello, i’m afraid i’m pretty green with expressions apart from good old loopOut(“cycle”) 😀

    Might anyone know how I could link the position of a layer to the first line of a text range selector in another layer?

    I did look at Dan’s response to this thread… but i’m afraid i’m not clever enough to adapt it to suit…

    Many Thanks, Dobbo.

  • Christopher Doulgeris

    January 6, 2023 at 12:10 am

    Hi! I know that I’m a decade late to replying, but I just discovered that .sourceRectAtTime() works for text layers with a range selector if the range selector is changing the scale to 0%.

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