Skip to main content
Bram Hoekstra
Inspiring
July 26, 2021
Answered

How to change position expression based on a checkbox control in another comp than the layer?

  • July 26, 2021
  • 2 replies
  • 1801 views

I'm build a script to make film credits.

 

I want to change the position expression of a layer when a checkbox is active or not.

 

Like the default position expression positions the first heading just out of the edges of the comp and the scroll expression positions the first heading in the middle of the comp and is scrollable with a slider control.

 

I already figured out this should be an if/else statement as you can't really do anything else with a checkbox control, but how to actually write this, I'm not certain of.

This topic has been closed for replies.
Correct answer Mathias Moehl

you can use this pattern:

 

var result;
if(...link to checkbox here...){
    result = ... expression 1 here ...
}
else {
    result = ... expression 2 here ...
}
result


now expression 1 is used when checkbox is checked and expression 2 if not

2 replies

Community Expert
July 26, 2021

Here are a couple of things you need to think about when creating scrolling or rolling text. 

 

Credit rolls and scrolling text will "judder" if the speed is wrong. Edges of text will flicker, especially with small fonts, unless the text moves exactly the same number of pixels every frame. The optimal speed of a credit roll or text scroll depends on the frame rate of the comp. Just animating a slider for this kind of motion is almost always a very bad idea because of the judder or stroboscopic effect and the aliasing problem with small type.  There are ways around these problems. 

 

It is almost always more efficient to create a credit roll in Illustrator and import that file into After Effects because formatting fonts is much easier and faster there. AI vector files that are just text or just text converted to shapes also render very quickly. If you want to use a text layer, that is also OK, it just takes longer to layout the text and it's hard to see past the bottom of the frame.

 

Now let's talk about finding the edge of the text or vector layer. You can use sourceRectAtTime() to find the size of a text layer. combine that with .left, .top, height, width, and turning on extends and/or setting time will allow you to accurately position type at the edge of the frame. 

 

Using time - inPoint will give you control over when the roll starts without keyframes. 

 

Using thisComp.frameDuration will let you count frames and use that as a multiplier for position changes that keep the text moving a whole number of pixels every frame.

 

You can certainly use a check box to start a scroll or roll in the middle of a frame, but you probably also want to allow the text to not move for a certain number of frames before it starts moving.

 

Let's talk about if statements to start with. The effects control checkbox returns a value of 0 (zero) or 1 so all that is needed is a simple if/else expression. I am going to assume that you put your Expression Controls on the text layer because that is the most efficient way to do it. You can then save the entire animation as an Animation Preset and use it anytime you want. This is what the basic if statement looks like:

 

 

strtPos = effect("Start Position")("Checkbox");
txt = thisLayer.sourceRectAtTime();
txtTop = txt.top;

if (strtPos == 0){
	sp = [thisComp.width, thisComp.height] / 2;
}
else{
	sp = [thisComp.width/2, thisComp.height - txtTop]
}

spd = 6; // pixels per frame
stTime = time - thisLayer.inPoint;
frmNum = stTime / thisComp.frameDuration;
mov = frmNum * spd;

[sp[0], sp[1] - mov];

 

 

6 pixels per frame is a good speed. 

 

You can throw in another check box and txt.width + txt.left to change the text from scroll to roll. You can substitute height and width for sourceRectAtTime() if you want to use the method for AI layers. You can even add and easeOut method and frame count to smoothly start a scroll or roll over a few frames and then continue at a constant speed. I've done most of that in my standard text and layer roll and scroll animation presets.

 

I hope this helps you get started. Setting the speed using frame counts is a much more reliable way of getting a good roll/scroll move than just guessing and hoping. All hardware-based title systems used in broadcast work this way. constantly moving text you are expected to be able to read always moves at a constant speed and exactly an even number of pixels (scan lines) per frame. 

 

 

Mathias Moehl
Community Expert
Mathias MoehlCommunity ExpertCorrect answer
Community Expert
July 26, 2021

you can use this pattern:

 

var result;
if(...link to checkbox here...){
    result = ... expression 1 here ...
}
else {
    result = ... expression 2 here ...
}
result


now expression 1 is used when checkbox is checked and expression 2 if not

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
Bram Hoekstra
Inspiring
July 26, 2021

Thx for your reaction.

 

Should I put this on the checkbox control or on the position property of the layer where the expressions have to be applied to?

Mathias Moehl
Community Expert
Community Expert
July 28, 2021

You always apply the expression on the property whose value should be changed by the expression. Hence, you need to apply it to the position properties.

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects