This iExpression is applied to the Focus Distance of an After Effects camera, and makes sure that a particular layer always stays in focus. You can also transition the focus from one layer to another one.
If you want to keep one layer in focus all the time, just enter the name of the layer in "Focus Layer 1" and apply the iExpression.
If you want to transition between several layers, enter additional layer names in "Focus Layer 2", "Focus Layer 3" and so on.
Then, add keyframes to the Focus Distance (you can add keyframes to a property, even if an expression is applied to it); set it to 1 to get "Focus Layer 1" in focus, and so on. Note that with keyframes, you cannot control "how" to transition the focus from one layer to the next: if you have keyframes for "1" and "3", the camera focus directly transitions from layer 1 to layer 3 without focusing on layer 2 inbetween. To make this possible, the expression considers only the keyframe values,not the easing between them.
However, you still have full easing control with the "Transition" parameter of the iExpression.
Focus Layer 1-30
name of the layer that should be in focus when you keyframe the focus to the respective value.
Determines how to transition from one focus layer to another, if you keyframe the focus.
Link Manual Transition
If the transition type is set to "manual", link a slider to this to control the focus transition from the previous to the next. Keyframe the slider to start with a value of 0 at the beginning of each transition and 100 at the end of each transition. How to transition from 0 to 100 controls precisely how the focus of the transition is done.
Animate this property if you want to temporarily move the focus away from the focus layer. You can link this to a slider and apply a wiggle to the slider, for example, to simulate some "pumping" of the auto-focus.