Skip to main content
New Participant
May 25, 2021
Answered

How to make number follow trim path

  • May 25, 2021
  • 3 replies
  • 3098 views

Looking for guidance.

 

I am building a Bar Chart graph using Trim Paths and have been trying to link the percentage to the length of the path so that the number follows the end of the trim path from zero to the designated length.

 

I have pickwhipped a null to follow the 'end' of the trim path but this doesn't work.

I can do it with a shape layer (rectangle) adding a null but can't work it out with a Trim Path.

 

Reaching out for help!

 

Thanks in advance.

This topic has been closed for replies.
Correct answer Kyle Hamrick

Under Window > Scripts you should see Create Nulls from Paths. This comes with AE. 

In the script panel that appears, one of the options is Trace Path. Make sure you have the desired path selected, and then click that. It'll generate a null that follows along your path. 

You can get rid of the keyframes and expression it created in the "Progress" property on this null, and then pickwhip that to your Trace Path. You should now be able to attach anything you like to this null, and have it follow the path progress perfectly.

3 replies

Community Expert
May 26, 2021

If you want to animate the size of a bar you have two options. Use a wide stroke and use Trim Paths or create a Rectangle Shape layer and animate the size. Both of these techniques will give you a value that you can convert to a specific range. 

 

For example, if I wanted the minimum and maximum value of a graph to be zero to 1,00 and the maximum height of the bar was 500 pixels I would add an Expression Control Slider to the Bar Graph shape layer and then use this expression for the source text of a text layer and for the Rectangle 1/Rectangle Path 1/Size, and Transform Rectangle 1/Anchor Point:

// Source Text for Bar 1
t = clamp(thisComp.layer("Bar Graph").effect("Bar 1")("Slider"), 0, 100);
t.toFixed(2);

//Contents/Rectangle 1/Rectangle 1/Position
x = 40;
t = clamp(effect("Bar 1")("Slider"), 0, 100);
y = linear(t, 0, 100, 1, 500);
[x, y]

// Contents/Rectangle 1/Transform Rectangle 1/Anchor Point
x = 40;
t = clamp(effect("Bar 1")("Slider"), 0, 100);
y = linear(t, 0, 100, 1, 500);
[x, y]

I use Clamp to set the minimum and maximum values for the Expression Control Slider that controls the height of the bar. The text value is rounded to 2 decimal places using toFixed(2) because it is easier to deal with than rounding the values.

 

The Linear method in the Size expression changes the 0 to 100 value of the slider to 0 to 500. You would use 0 to 100 if you were using trim Paths.

 

The anchor point is offset by half the height of the rectangle so that the rectangle size changes from the bottom instead of the middle.

 

This is what the comp looks like: 

I rearranged the workspace to give you a better look at the structure of the comp.

Here's a sample comp for you to play with.

Kyle Hamrick
Community Expert
Kyle HamrickCommunity ExpertCorrect answer
Community Expert
May 25, 2021

Under Window > Scripts you should see Create Nulls from Paths. This comes with AE. 

In the script panel that appears, one of the options is Trace Path. Make sure you have the desired path selected, and then click that. It'll generate a null that follows along your path. 

You can get rid of the keyframes and expression it created in the "Progress" property on this null, and then pickwhip that to your Trace Path. You should now be able to attach anything you like to this null, and have it follow the path progress perfectly.

New Participant
June 2, 2021

Thanks this worked for me!

Dan Ebberts
Community Expert
Community Expert
May 25, 2021

It will probably look something like this:

 

L = thisComp.layer("Shape Layer 1");
p = L.content("Shape 1").content("Path 1").path;
pct = L.content("Trim Paths 1").end;
L.toComp(p.pointOnPath(pct/100));
Known Participant
October 21, 2022

Hey Dan, this is awesome. It works as intended but when I click the "reverse path direction On" for the trim paths my null

it goes the other way. Is there anything that I could add to this code to account for that? Either automatically or with a checkbox for example?

Dan Ebberts
Community Expert
Community Expert
October 21, 2022

I don't think you can detect the reverse switch automatically, but you could add a check box to the shape layer and do this:

L = thisComp.layer("Shape Layer 1");
cb = L.effect("Reverse")("Checkbox").value;
p = L.content("Shape 1").content("Path 1").path;
pct = L.content("Trim Paths 1").end;
pct = cb ? 100 - pct : pct;
L.toComp(p.pointOnPath(pct/100));