Activity › Forums › Adobe After Effects Expressions › automated light sweep
-
automated light sweep
Posted by Jack Parks on March 13, 2011 at 2:29 pmHello
At work we constantly have clients asking for cc light sweep over the text. Can anyone suggest an expression that would automatically run from 100 pixels from the left of the text to 100 pixels right, that would take the time length of the text layer? If possible the left and right value could be adjustable and maybe a value of loops could be added?
Any ideas would be really helpful as doing this with keyframes gets repetative especially when text gets re positioned etc.
ThanksJack Parks replied 15 years, 2 months ago 2 Members · 9 Replies -
9 Replies
-
Dan Ebberts
March 13, 2011 at 3:52 pmOK – you’ll need to add 3 sliders to the text layer: Left Margin (set to 100), Right Margin (set to 100) and Duration (set to your desired sweep time). Add this expression, and set a layer marker wherever you want to trigger a sweep:
M = marker;
n = 0;
if (M.numKeys > 0){
n = M.nearestKey(time).index;
if (M.key(n).time > time) n--;
}
t = n > 0 ? time - M.key(n).time : 0;
leftMargin = effect("Left Margin")("Slider");
rightMargin = effect("Right Margin")("Slider");
duration = effect("Duration")("Slider");
for (i = 0; i <= width; i++){
temp = sampleImage([i,height/2],[0.5,height/2],true,time);
if (temp[3] > 0) break;
}
leftMargin = i - leftMargin;
for (i = width; i >= 0; i--){
temp = sampleImage([i,height/2],[0.5,height/2],true,time);
if (temp[3] > 0) break;
}
rightMargin += i;
x = linear(t,0,duration,leftMargin,rightMargin);
[x,value[1]]
Dan
-
Jack Parks
March 13, 2011 at 9:56 pmThanks, this looks great, I will give this a try.
Thanks again. -
Jack Parks
March 14, 2011 at 3:58 pmHi Dan
I have been trying your expression and it seems to work but it’s making after effects go a little erratic, sometimes the expression stops working, the interface graphic glitches and there’s error messages. Is it just my setup? (Mac Snow Leopard CS4)
It’s a bit odd.
Any ideas?Thanks
-
Dan Ebberts
March 14, 2011 at 5:38 pmWhat are the error messages?
The expression includes a hack to find the edges of the text layer and there may be scenarios where it doesn’t work well. Hard to say without seeing how you have things set up though.
Dan
-
Jack Parks
March 14, 2011 at 5:50 pmThanks for your reply, after effects doesn’t seem to be happy with it, please could I bother you again?
To avoid the problem could the expression work by finding the center and then the left/right margin sliders determine the start and end? or a value is entered say 1000 pixels to travel across.
Thanks again for your help. -
Dan Ebberts
March 14, 2011 at 6:35 pmThis version will work with the margins based on where the anchor point is (so if your text is left justified, the right margin will need to be a lot bigger than the left):
M = marker;
n = 0;
if (M.numKeys > 0){
n = M.nearestKey(time).index;
if (M.key(n).time > time) n--;
}
t = n > 0 ? time - M.key(n).time : 0;
leftMargin = anchorPoint[0] - effect("Left Margin")("Slider");
rightMargin = anchorPoint[0] + effect("Right Margin")("Slider");
duration = effect("Duration")("Slider");x = linear(t,0,duration,leftMargin,rightMargin);
[x,value[1]]
Dan
-
Jack Parks
March 15, 2011 at 3:21 pmHello
I have been testing out the expression and simplified it a little.
Does it look ok? Would there be any obvious glitches?
How would you specify a frame amount in the duration? (1 at the moment = 1 second).Thanks for your help with this.
M = marker;
n = 0;
if (M.numKeys > 0){
n = M.nearestKey(time).index;
if (M.key(n).time > time) n--;
}
t = n > 0 ? time - M.key(n).time : 0;
leftMargin = transform.position[0] - effect("Width")("Slider");
rightMargin = transform.position[0] + effect("Width")("Slider");
duration = effect("Duration")("Slider");x = linear(t,0,duration,leftMargin,rightMargin);
[x,value[1]] -
Dan Ebberts
March 15, 2011 at 3:54 pmIf you want to enter the duration in frames, just change the appropriate line to this:
duration = effect(“Duration”)(“Slider”)*thisComp.frameDuration;
Dan
Reply to this Discussion! Login or Sign Up