Copy link to clipboard
Copied
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.
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 t
...Copy link to clipboard
Copied
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));
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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));
Copy link to clipboard
Copied
You are the very best! You know that, right?
Copy link to clipboard
Copied
I think you can detect that reverse switch after all. This seems to eliminate the need for the checkbox:
L = thisComp.layer("Shape Layer 1");
p1 = L.content("Shape 1").content("Path 1");
p = p1.path;
pct = L.content("Trim Paths 1").end;
pct = p1(1) == 3 ? 100 - pct : pct;
L.toComp(p.pointOnPath(pct/100));
Copy link to clipboard
Copied
Now that's an elegant solution. Love it.
I'm still learning JS to do some stuff on expressions (i think it was one of you guys that recommended the ukramedia course, witch is pretty good).
But one thing that I still can't fit to my mind is like on the 4th line you define the pct as variable, but on the 5th you set it as ternary operation, I know it works, but can you tell why it doesn't override the variable set on the 4th?
Why it doesn't conflict with the 4th?
Just checked the code again and I think I might understood: is it something like on the 4th you define pct as the trim paths' end, then on the 5th you use it's value and redefine it with the ternary operation?
Like on the 4th line it does something but on the 5th it does something else using the 4th's value
Is that it?
Thanks again
Copy link to clipboard
Copied
Basically, the 5th line says "if the reverse switch is on, flip the value of pct, otherwise leave it as defined in line 4".
Copy link to clipboard
Copied
I see, makes total sense now, thank you.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Thanks this worked for me!
Copy link to clipboard
Copied
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.