Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Text range selector position value expression

Participant ,
Feb 17, 2021 Feb 17, 2021

Hi,

Is there any way to have an expression so the null layer follows the text range selector x and y position even when we have multiple lines of text? 

Thank you in advance.

TOPICS
Expressions , How to
3.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 17, 2021 Feb 17, 2021

I have seen what Dan did a few years ago when expression provides tracking position on X-axis but I can not figure out how this expression could be adjusted to follow position on Y-axis as well so it could be used for multiple lines text. Thank you in advance for any help. This is old Dan's expression wor X position :

 

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]

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 18, 2021 Feb 18, 2021

Works no different for the Y position, so I'm not clear what specifically you are having difficulty with. Of course the expression might benefit from smartening it up by adding internal string processing to have a safety to determine whether or not something is actually on a new line, but otherwise you only need to duplicate the relevant lines that reference X axis and width parameters and refactor them to scan in Y direction and height.

 

Mylenium

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 18, 2021 Feb 18, 2021

Thank you Mylenium.

I will try that.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 23, 2021 Feb 23, 2021

I am still trying to figure this one out. I am able to adjust Dan's code to follow Y-axes but I am unable to make it work to follow x and y at the same time. Is this possible? I would like when for example the second line of text appears my null (which is run by expression) moves down and to the left so it starts following alpha information of that row. Thanks in advance.

I was trying to modify Dan's script for x and y but I am getting an error message and I am not sure if this is the right approach. This is that (not working) code.

 

L = thisComp.layer("text");
gotIt = false;
for (i = thisComp.width; i >= 0; i--)
{
for (j = thisComp.height; j >= 0; j--){
temp = L.sampleImage([i,j],[0.5,0.5],true,time);
if (temp[3] > 0){
gotIt = true;
break;
}
}
if (gotIt)
[i + width/2,j + height/2]
else
L.transform.position + [width/2,height/2]
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Feb 18, 2021 Feb 18, 2021

AFAIK, this is not possible, in an elegant manner, with current constructs. What you can do is to, internally, deconstruct the text into individual lines but before that, you will have to set the Based On property to Characters. And priorly, you will have to calculate the total number of characters for the text string. And then find out which row the current/active text characters appears within. And the list goes on ... .

There is obviously quite a fair bit of work to be done. Perhaps a quicker algorithm is viable if you stated clearly what it is that you are trying to achieve.

Very Advanced After Effects Training | Adaptive & Responsive Toolkits | Intelligent Design Assets (IDAs) | MoGraph Design System DEV
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 18, 2021 Feb 18, 2021

Thank you Roland,

 

What I am trying to do is to build a template with range selector/opacity text reveal where still image of the hand will trace the text reveal. So I was thinking if we are able to get the position value of the range selector and provide that information to the hand that will be exactly what will work for this template. Thank you in advance.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 18, 2021 Feb 18, 2021

You can pull the length of a line of text using sourceRectAtTime().

The Range Selector can be set to use a percentage.

The distance the hand moves can be calculated by using the start and end values.

If you read the current position of the hand layer as a percentage of the total distance traveled and you combine that with the width of the text layer, you should be able to drive the percentage of the range selector end value by that number and get the opacity to follow the movement of the hand in a straight line. You would have to subtract the width of the hand to get the edge to line up, but the math should be fairly simple. 

 

If you need to adjust the movement of the hand layer to cover the text that involves another expression. The easiest approach would be to animate the movement of the hand and then just calculate the percentages and offset and let the range selector follow the movement.

 

This would work with a single line of text. If you have multiple lines of text then the position of the hand becomes much more difficult to calculate, but it could probably be done as long as the lines of text were all about the same length. 

 

I don't have the time to fiddle with it now, but if I get some free time I might take a stab at it later. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 18, 2021 Feb 18, 2021

Turned out not to be that difficult. 

 

Without taking into account the position of each layer all you need is this:

  • retrieve the txtWidth of the text layer using sourceRectAtTime()
  • Subtract half the txtWidth from half the comp width to get the starting position of the text layer
  • define the Hand layer and retrieve its position
  • get the xCover percentage of the position of the handLyr by subtracting the xPosition fron the txtStart value and dividing that by the txtWidth
  • multiply the xCover percentage by 100 to turn it into a usable value for Start
  • subtract the percentage of the hand layer's width from the wipePos and you're done.

 

 

 

 

txtWidth = thisLayer.sourceRectAtTime().width;
txtStart = (thisComp.width/2) - (txtWidth / 2);
handLyr = thisComp.layer("Hand");
xPos = handLyr.position[0];
xCover = (xPos - txtStart) / txtWidth;
wipePos = xCover * 100;
wipe = wipePos - 4 // padding for hand layer
if (wipe < 0){
	Start = 0;
	}
else{
	Start = wipe;
}

 

 

 

 

 The comp looks like this:

WipeOnTxt.gif

All that is left is to add in some compensation for the position of the text layer and replace my placeholder rectangle with an image of a hand.

 

If you have multiple lines of text and you have created the proper path for your hand layer you can divide the sourceRectAtTime().height by the number of lines and work out the percentages so that the wipe follows the text reveal. It's just a little more fiddling.

 

Making the motion path of the hand layer follow the progression of the text animator would involve the same kind of thinking but a little more math. You would also have to retrieve the position of the text box. The general idea is the same. Maybe I'll try and figure that one out later.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 19, 2021 Feb 19, 2021

Thank you so much, Rick. This is great. Thank you for your time and your help.

All the best.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 09, 2025 Apr 09, 2025

This is great Rick thank you so much.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 13, 2025 Apr 13, 2025
LATEST

 

Yes, use this expression on the Null’s position to follow the text range selector across multiple lines:
txt = thisComp.layer("YourTextLayer");
anim = txt.text.animator("Animator 1").selector("Range Selector 1");
x = txt.sourceRectAtTime().left + txt.sourceRectAtTime().width * (anim.start + anim.end) / 200;
y = txt.sourceRectAtTime().top;
txt.toComp([x, y])

Make sure to adjust the YourTextLayer and selector names according.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines