: After Effects expressions to sum numbers and control charts I would like to build a project in which I will change two numbers and all of the following take place automatically! I'll Explain...
I would like to build a project in which I will change two numbers and all of the following take place automatically! I'll Explain...
Part 1:
I have two layers, "Number 1" and "Number 2". Suppose I give "Number 1" the value 15 and "Number 2" the value 5. Automatically I want a new layer to sum these numbers (20).
Part 2:
Next, I would like to built a chart below to update automatically according to the numbers that I gave.
From the above sum, I want the layer with the value 20 to automatically correspond to 100% in the chart. So the chart shapes change automatically and understand that "Number 1" with the value 15 is 75% (15*100/20) and "Number 2" with the value 5 is 25% (5*100/20).
Probably I need for the value of the numbers a Solid with a Numbers effect and not a text? And if someone knows the expressions...
More posts by @Becky351
1 Comments
Sorted by latest first Latest Oldest Best
This is actually pretty easy to set up with a few expressions and control inputs. All we need is two control inputs and expressions on the various layers to pull the values from the inputs.
1. Slider Control
Create a null object (Layer → New → Null Object) and add a slider expression control to that null object by going to (Effect → Expression Controls → Slider Control). This gives us a handy slider in the Effects panel that we can use as an input in expressions.
You should have something like this:
2. Text layer
Create a new text layer to show our input from the slider. Open the "Text" property and alt+click the stopwatch next to "Source Text" to add an expression to the text itself. The expression we need is:
Math.round(thisComp.layer("Val 1").effect("Slider Control")("Slider"))
The Math.round() just means we get an integer, otherwise we get a ton of decimal places. The rest simply gets the value from the slider from the correct layer.
3. Putting it all together
Repeat the same steps as above for your second input (so you need a total of 2 null objects, each with a slider, and 2 text layers with an expression pulling the value from the correct slider (simply change layer("Val 1") in both expressions to reference the correct layer names).
For your sum total text you need another text layer with an expression pulling both slider values and adding the values together. Something like:
val1 = thisComp.layer("Val 1").effect("Slider Control")("Slider");
val2 = thisComp.layer("Val 2").effect("Slider Control")("Slider");
val1 + val2
4. Chart bars
We can use the same concept to set up our bars. Create your bars at 100% width (you should also move the bar's anchor to the far left, or where ever you want them to scale from). You can then add an expression on the layer's scale property to pull in the slider values and do the calculations you already mention. Something like:
val1 = thisComp.layer("Val 1").effect("Slider Control")("Slider");
val2 = thisComp.layer("Val 2").effect("Slider Control")("Slider");
t = val1 + val2;
[ val2*100/t, 100 ]
The finished thing looks something like this; just select your null objects and adjust the sliders and everything will automatically update for you:
This was a quick example and could definitely be improved; the text could probably just be done on a single layer and the bars update on the raw slider values while the text only shows a rounded integer, which may or may not be what you want...
Actually, here's a more compact version with both sliders added to a single text layer:
You can read more about using expressions here:
Learn expression basics to link animations in Adobe After Effects
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.