• Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
    Dedicated community for Japanese speakers
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
    Dedicated community for Korean speakers
Exit
0

How to Animate Progress Bar with checkbox control effect.

Community Beginner ,
Aug 30, 2021 Aug 30, 2021

Copy link to clipboard

Copied

I'm making a progress bar, and i wanna animate the X Position, so the bar moves from -661 to 1029. I linked it to a Null Layer with a Checkbox Control Effect, so when the Checkbox is On, the bar moves, and when the Checkbox is Off, the bar stops in that frame. I'm trying to make it as automated as possible so I'd only have to put On/Off keyframes in the Checkbox Control effect. Is there any expression for that??

I'd also need to change the time it takes the bar to complete from left to right.

TOPICS
Expressions , How to , Scripting

Views

566

Translate

Translate

Report

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

correct answers 1 Correct answer

Mentor , Aug 31, 2021 Aug 31, 2021

Here you go:

 

 

chk = thisComp.layer("Animation Controller").effect("Run PBar Animation")(1);
prevAnimations = 0 - thisComp.frameDuration;

for (i = 0; i <= timeToFrames(time); i++)
{
	if (chk.valueAtTime(framesToTime(i)) == 1)
	{
		prevAnimations += thisComp.frameDuration;
	} else
	{
		continue;
	}
}	
prevAnimations;

 

 

You need to have a layer "Animation Controller" with a checkbox "Run PBar Animation" to turn on/off the animation. The checkbox should be the first control in the layer effects stac

...

Votes

Translate

Translate
Mentor ,
Aug 31, 2021 Aug 31, 2021

Copy link to clipboard

Copied

Here you go:

 

 

chk = thisComp.layer("Animation Controller").effect("Run PBar Animation")(1);
prevAnimations = 0 - thisComp.frameDuration;

for (i = 0; i <= timeToFrames(time); i++)
{
	if (chk.valueAtTime(framesToTime(i)) == 1)
	{
		prevAnimations += thisComp.frameDuration;
	} else
	{
		continue;
	}
}	
prevAnimations;

 

 

You need to have a layer "Animation Controller" with a checkbox "Run PBar Animation" to turn on/off the animation. The checkbox should be the first control in the layer effects stack. If not, alter the number at the end of the first line or pigwhip the checkbox into this line.

Also, you need a pre-comp with time remap enabled. This code goes to the time remap proberty of this pre-comp.

Inside this pre-comp, you just create your progress bar animation with keyframes. I used a shape layer and animated it's x-size from 0 to 1920, but you are free to do whatever you like here.

 

In AE, there is no way to transport information from one frame to another. Therefore, the only solution to the "hold value" problem is to go through the whole timeline and recalculate, what happended there. This isn't very smart in general and if you have a very long timeline or massive calculations, you'll notice a performance gap when running such a code.

 

I added my project file for better understanding.

 

*Martin

 

 

Votes

Translate

Translate

Report

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 Beginner ,
Aug 31, 2021 Aug 31, 2021

Copy link to clipboard

Copied

THANKS!! It actually worked!!

Votes

Translate

Translate

Report

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 ,
Aug 31, 2021 Aug 31, 2021

Copy link to clipboard

Copied

quote

I'm trying to make it as automated as possible so I'd only have to put On/Off keyframes in the Checkbox Control effect.

 

Not possible. Something has to be animated to even determine whether the bar should even grow or not. Outside a checkbox the only way to do that would be to constantly check if the layer actually moves or not, which would require some considerably more code than what @Martin_Ritter provided.

 

Mylenium

Votes

Translate

Translate

Report

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
Mentor ,
Sep 01, 2021 Sep 01, 2021

Copy link to clipboard

Copied

LATEST

Instead of

 

prevAnimations += thisComp.frameDuration;

 

you can add somevalue which represents the grow speed of the bar (e.g. 10px / sec) and instead of putting this to time remap, the expression controls the size or position of the progress bar. It's nearly the same code and would not require a pre-animated progress bar.


If some value is now dynamically, e.g. depending on the duration of the current pre-comp, this would be the highest level of automation I can think of in a real-world scenario.

In the end, you can also define other triggers to start/stop the grow, so you even don't need keyframes on the checkbox. But of course this highly depends on the use-case.


A bit more code, but for sure possible.


*Martin

Votes

Translate

Translate

Report

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