You are on page 1of 26

1CREATIONS

EAFTEREFFECTS

2INTRODUCTION

INTRODUCTION
Hello,andwelcometoAfterEffectsExpressionsBasics.ImDavidAlex,VFXArtistandbigfanofAfter
Effects,andImgoingtowalkyouthroughthebasicconceptsofusingexpressionsinAfterEffects.
In this document, well be looking at what expressions are, how they work and how to use them properly.
By the end, you should not only beabletousesomeofthemostcommonandusefulexpressions butalso
havetheunderstandingrequiredtoexpandyourknowledgetoanadvancedlevel.
Illassumethatyouveneverusedexpressionsbeforetomakeexplanationsandambiguousareasabit
easiertoworkwith.Ifyouveseenasectionbefore,feelfreetoskipit.
IllalsoassumethatyouhaveareasonableamountofknowledgeonAfterEffects.Atleastknowyourway
aroundtheapp,thepanels,creatinglayers,effectsandkeyframing.
Beforewegetstarted,IdliketoclarifysomesyntaxandwordsIllbeusing::
Ratherthanfillingthisdocumentwithscreenshots(andmakingitbigger),goingthroughmenuslikethis:
Willbeshownlikethis:Layer>New>Solid...
Shortcutswillbewritteninbrackets().
PropertyreferstoOpacity/Rotation/Scale/Position/AnchorPoint...basicallythepropertiesofalayer,
thoughsometimesIllrefertoacontrolwithanexpressionasaproperty(foreaseofunderstanding).
InitialValuewouldbethevaluetypedintotheboxoftheproperty.Thisisnotwhattheexpression
produces.Itbecomesconfusingreferringtothis,butthisshouldmakethingseasiertounderstand.
FinalValuereferstothevalueproducedbytheexpression,orratherthevaluethatthepropertyhasinthe
endofallcalculations.
Expressionswillappearinaboxlikethis::
If(thisLayer.numKeys>2),loopOut(cycle,2)}else{value}
Thatsaboutit.
Also, Id suggest that you make friends with the Help system (if you havent already). Go to Help > After
Effects Help and check out the system (or Help > Expression Reference). We can use this document
alongside the Help to explain stuff, and itd be good toreferyoutosomeofthethings there.Thoughsome
thingsarehardtounderstandthere,Illtryexplainthemhere.
2IdeastoCreations|AfterEffectsExpressionsBasics(CC)BYNCSA
ProjectrhEffect
Comp1WhiteSolid1

3INTRODUCTION
IfyoureworkinginCS5,youveprobablynoticedthattheHelpsystemisonlinenow.Ifyoudonthavea
constantconnection,youcandownloadtheHelpfromthesite.
http://help.adobe.com/en_US/aftereffects/cs/using/after_effects_cs5_help.pdf
ItsaPDFabout30MB.Itsupdatedquitefrequentlyandcontainsbookmarkstoeasenavigatingthroughit.
Id also like to mention that this book is based off examples, rather than teaching facts, whichIfindis an
easier way to understandsomething.Tothateffect,wewontuseprojectfiles,wellbuildthem.Inthis way,
we can see the whole process and heck might even learn something newotherthanexpressions.Illkeep
thingssimpleanddescribethestepsasbestIcan.
Allright,havingsaidallthat,werereadytogetstarted!
3IdeastoCreations|AfterEffectsExpressionsBasics(CC)BYNCSA

4WHATAREEXPRESSIONS?

WHATAREEXPRESSIONS?
An expression is a piece of code thats inserted into a property to calculate its final value. These
calculations can range from simple addition or multiplicationoperations tocomplex functions thatvary with
otherproperties andcontrols andevenwithtime.Thepartthatmakes expressions funandextremely useful
is that they can be usedtoconnectproperties andcontrols tooneanother,whichwelldefinitely havetogo
through.
TheAdobedocumentationhasaninterestingwayofexplainingwhatexpressionsare(page609inthePDF,
AboutExpressionsinHelpsystem):
Whenyouwanttocreateandlinkcomplexanimations,butwouldliketoavoidcreatingtensorhundredsof
keyframesbyhand,tryusingexpressions.Anexpressionisalittlepieceofsoftwaremuchlikea
scriptthatevaluatestoasinglevalueforasinglelayerpropertyataspecificpointintime.Whereas
scriptstellan
applicationtodosomething,anexpressionsaysthatapropertyissomething.

Not as complicated anexplanationas onewouldexpectfromaHelpsystem.Its nicethatthey getspecific


and say it evaluates to a single value for a single property at a specific time. Which we can interpret as
meaningitcanchangeovertime.
Also, its important that at this pointImentionthatexpressions shouldonly beusedtoeitherdosomething
that keyframes cannot or do something that would require toomany keyframes.Theres noneedtoaddan
expressiontomakesomethingmoveacrossthescreenwhenjust2keyframescanveryeasilydothatjob.
ButImsurethemostimportantquestionyoureaskingis...

Howdoesoneapplyexpressions?
Anypropertyorcontrolwithastopwatchcanhaveanexpression,whichisprettymucheverycontrolin
AfterEffects.Inordertoaddanexpression,simplyAlt+Clickonthestopwatchoftheproperty:
4IdeastoCreations|AfterEffectsExpressionsBasics(CC)BYNCSA
Afewthingshappenwhenyoudothis:
1.Belowthecontrol,yougetExpression:~referringwhatitsapplyingto,aswellasafewbuttons.
Welllookintotheirusesaswegoalong.

5WHATAREEXPRESSIONS?
2.Inthetimeline,atextboxappears(whichwecanrefertoastheExpressionBox)anditimmediately
hasacodethatreferstothecurrentcontrolitsappliedto.3.Thenumbersofthecontrolturnred,which
isagoodindicationofwhetheranexpressionisappliedto
somethingifyourenotinthetimeline(likeintheEffectspanel).4.Alittletriangleappearsonthe
farleft,whichtogglestheappearanceoftheexpressionbox.
When you alt+click a control, you immediately get a code that refers to that control. If you were to click
away at this point,theexpressionwouldbeappliedbutnothingwouldreally changebecausewevejusttold
thecontroltouseitselftoproduceitsvalue,ortoputitbetter,touseitsinitialvalueasitsfinalvalue.
Soifyouweretoalt+clickonScale,youdgettransform.scaleandOpacitytransform.opacity.
This is a good way to remind you what controls arereferredtointheexpressionworld.If,say,youwanted
your scale to be equal to the opacity, youd simply alt+click on the Scales stopwatch and insert
transform.opacity as the expression. What were telling AE is take the transformproperty ofopacity and
makeitthevalueforthiscontrol.
Theressomethingelseyoushouldnoteaswell:
5IdeastoCreations|AfterEffectsExpressionsBasics(CC)BYNCSA
Asyoucanseeabove,Scale,RotationandOpacityhaveexpressions(thereddigits),howeverthe
stopwatchforOpacityisactive.Thisisbecauseithaskeyframes.
Thestopwatchstillworksasusual.Ifyouclickonit(withoutholdingAlt),youllapplykeyframesasusual.
Wellgointoworkingwithkeyframesabitlater,butletsgetthroughthebasicbasicsfirst.
ItsalsoimportanttonotethatexpressionsareCASESENSITIVE.Ifyouhadtransform.Rotation,youdget
anerror.Keepthisinmind(itgetannoyingsometimes).

6WHATAREEXPRESSIONS?

ExpressionvsInitialValue
Soletsstartwithanexamplethat,althoughverysimple,willexplainaveryimportantpoint.
Createanewcompwithwhateverdimensionsyoulike.Iusuallygowith720x48025fpsSquarePixels10
secondsformyexperiments.GoaheadandaddaSolidwithadifferentcolourfromthebackground.
Headdowntotheopacity(T)andwellAlt+Clickandtypeinthissimpleexpression:
50
Iwarnedyouitdbesimple.
So click away and see what happens. Our final value (in red)is now50.Youllnoticethatwecantdirectly
tell what the initial value was. So click on the red text and youll notice that the initial value is still 100
(remember initial value is what we type in).Typeinsomethinglike20.Click away andyoullnoticethatthe
finalvalueisSTILL50!!Tryanimatingtheopacitywithkeyframes...yep,exactly!
Sowhatarewesayinghere?
ExpressionsalwaysoverridetheInitialValueapplied.
Thismeansthatanycontrolwithanexpressionappliedtoitwillusetheexpressionsresultratherthanthe
initialvalue,becauseotherwiseitdbepointlesstohavetheexpression,right?
Initial value, however, isnt completely ignored.Ifyouweretodisabletheexpressionby clickingthe= sign,
or alt+clicking the stopwatch again, youll notice it doesnt reset to the default value but goes tothevalue
welasttypedinasInitialvalueintheexperimentabove.
However,expressionscanusetheinitialvalueaspartofitscalculationtoproduceanothervaluethatvaries
withtheinitialvalue.Thisisbestexplainedwith,yes,anexample.
6IdeastoCreations|AfterEffectsExpressionsBasics(CC)BYNCSA

7WHATAREEXPRESSIONS?

UsingVALUE
Expressionshaveasimplewayofreferringtotheinitialvalue,andthatis:value
VALUE,insimpleterms,referstotheinitialvaluethatyoutypeintothecontrol.Wecanrefertothisinitial
valueintwoways:
1.Thelongway(transform.opacityifwereinopacity)
2.Theshortway(value)
IalwaystaketheshortwaymainlybecauseIdonthavetoremembercodeandalsoitmakescopypasting
theexpressionsimpler.
HeadbackintotheOpacityanddeleteanykeyframesandsettheinitialvaluebackto100.Ifyoualt+click
onthestopwatch,youcanremovetheexpression.Alt+clickagaintoapplythisexpression:
value20
The first thing youll notice when you click outside the expression box is thatourfinalvalue(inred)is now
80. If we were to click and scrub the values, as soon as you let goyoullnoticethatwhateverinitialvalue
youvesetwillbetakenandhave20subtractedfromit.
Beforeyoustartquestioningthepracticalusesofthisconsiderascenario:
You have opacity animation of 0 > 100 > 50 > 0, but you found these middle values were too high, and
would like to reduce the range by 21 percent, its as simple as justheadingintotheexpressionandtyping
value21 , and what youll getis (021)> (10021)> (5021)> (021).Sinceopacity cantbeless than0,the
0keyframeswillremain0,whiletheothersbecome79and29respectively.
IfthiswereScale,wedhavethe0keyframesbeing21,inwhichcaseourobjectwouldflip!
So,dontunderestimatethepowerofvalue.Whenitcomestocreatinganimationpresets,itsavery
importantfunction.
Feelfreetomessaroundabitwithdifferentexpressionslikevalue(value20),value/2etc
7IdeastoCreations|AfterEffectsExpressionsBasics(CC)BYNCSA

8REFERINGCONTROLSTOOTHERCONTROLS

REFERINGCONTROLSTOOTHERCONTROLS
Thismayseemlikeabigjumpfromvalue,butitsactuallyaverysimpleprocess.
Expressions can be used to refer one control to another. Like say, to have Scale equal to Opacity at all
times. Wevecoveredthis examplealready.Butwhathappens ifwewantedtheScaleoflayer1tobeequal
tothescaleoflayer2,orbetteryet,half!
Itsnotassimpleastransform.scalebecausethiswouldonlyrefertothelayersownscale.Hereswhat
weddo::
Remember the four buttons that appear whenyouapply anexpression?Thefirstoneactivates/deactivates
the expression, the second one visualizes it, and the third is the pick whip. The last one there is a menu
whichactslikeashortcuttoapplyingexpressionfunctions.
Whatwereinterestedinhereisthepickwhip.
The pick whip is a dragdrop control that we use torefertoanothercontrol.Itworks liketheParentingpick
whip. What AE does is it takes whatever has been pickwhipped and turns the control were picking from
intowhatwerepickingto.
Anexpressionisautomaticallygeneratedwhichisjustoneofthebestthingsaboutit.
Inordertoshowthepowerofthepickwhip,letsbuildaCompforustoexperimentinwithallthisstuff.
Whatwelldoiscreatetwosquaresolids(400x400)andapplyGrid+Rampsowecandifferentiatethetwo
andseetheeffectsapplying:
8IdeastoCreations|AfterEffectsExpressionsBasics(CC)BYNCSA

9REFERINGCONTROLSTOOTHERCONTROLS
NoticethattheRampspointsareextremelyclosetooneanother.
Ivesetboththeirscalesto60.IllcalltheoneontheleftRed,andtheoneontherightGreen.
So, in order to get the pick whip working, we need to have the controls we want to pick visible. So, Ill
select Red and Green and press S to show their scales only. Ill then alt+click on Greens scale. Ill get
transform.scaleasexpected.
Now,IllclickandholdonthepickwhipanddragittoRedsscale::
9IdeastoCreations|AfterEffectsExpressionsBasics(CC)BYNCSA
IlElendWithClriginal

10REFERINGCONTROLSTOOTHERCONTROLS
EnsuringthatwegetthatgreyboxaroundRedsscale,whenweletgowegetthisexpressioninthebox:
thisComp.layer("Red").transform.scale
Now, our Green layers scaleis tiedtotheRedlayers scale.IfwescrubthescaleofRed,youllnoticethat
the Green follows suit. This is the most basic use of referral. Itdbefuntogoaheadandadd/2attheend
ofthisexpression,oreven*50,butletslookabitcloselyattheexpressionabove.
Asyourememberfrombefore,wehavetransform.scaleinvolved,howeverwehavealittlecodebeforeit.
ThiscodethisComp.layer(Red)issimplytellingAEthat:
InthisComp,gotothelayercalledRedandtakeitsscale.
Referralshaveaspecificsyntax.Firstwerefertothecompwewant,thenthelayerwewant,thenthe
propertywewant.Eachstepisseparatedbyafullstop:
COMP.LAYER.PROPERTY
Youdontnecessarily havetorememberthis becausethepick whipdoes allthis work forus.Allwehaveto
worry about is whether the control we want to pick is in view. Though you can think of it of leading the
expression to the control as if it were starting from the Projectpanel,movingintothetimeline,andlooking
forthepropertyyouwant.
Sowhatifyouwantedtopickwhiptoaneffect?WhatifwewantedtheothercolouroftheGreentobethe
othercolouroftheRed(whichisCyan)?Well,thisissimpleenough.
Asbefore,weneedtobeabletoseethecontrolsowecanpickwhipit.Intermsofeffects,therestwo
wayswecanviewthecontrols.
1.PressEtoviewtheeffectsappliedtothatlayer,aswellastheeffectscontrols.
2.LOCKtheEffectspanel.
In this case, we are pick whipping an effect to aneffect,sowecanusebothofthesemethods (ifweused
one, wedhavealotofthings showinginthetimelineandhavealongway topick whip,ifweusedtwowed
havetocreateanewEffectsViewerandthatwouldcrowdupourworkspace).
ItsjustthewayIpreferit,butdoasyouseefit.
SinceIcantpickwhipfromtheEffectspanel,ImgoingtolocktheviewwiththeRedlayersEffectsand
useEontheGreenlayerseffectinthetimeline.So,letsdoexactlythat.
10IdeastoCreations|AfterEffectsExpressionsBasics(CC)BYNCSA