Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Fade in and out script

  • Fade in and out script

    Posted by Robert Hallion on May 23, 2008 at 5:09 pm

    I was wondering if someone could help me with writing a simple script. I just want to have a script that I can run that change the opacity of the selected layer from 0 to 100% in 15 frames. And then have the opposite happen, 100 to 0.

    I can get it to work when referencing the first layer, and when using seconds.

    myComp = app.project.activeItem;
    myOpacity = myComp.layer(1).property(“opacity”);

    myOpacity.setValueAtTime(0, 0);
    myOpacity.setValueAtTime(1, 100);

    But is there a way to just reference the selected layer and I could do 1/2 and that will give me 15 frames on a 30fps project but not if I’m working with a 15fps project.

    Also, I’m new to AE scripting and I’m unsure where to get information on it. There seems to be very limited info, I can write some AS and I understand the concept but it’s confusing when you don’t know what to call objects in AE.

    Thanks!

    Kevin Camp replied 17 years, 12 months ago 2 Members · 2 Replies
  • 2 Replies
  • Kevin Camp

    May 23, 2008 at 10:46 pm

    i haven’t gotten into scripts much, but since this deals with a single layer, an expression like this ino the opacity expression field would work:

    n = 15 * thisComp.frameDuration;  //sets duration to 15 frames regardless of frame rate.
    if (time >= inPoint && time < outPoint-n) linear(time,inPoint,(inPoint+n),0,100);
    if (time >= outPoint-n) linear(time,outPoint-n,outPoint,100,0);

    it doesn’t add any key frames, it just bases the calculation off the layer’s in and out points. if you were to adjust the in or out points for the layer the opacity would be recalculated.

    i hope you can incorporate this into your script. i have found a lot of information on expressions on motionscripts.com, there is a section on scripts too. i believe there is a scripting/expression pdf on the ae install disk that goes into some detail about the ae specific objects (i specifically remember finding one on the ae7 disc).

    Kevin Camp
    Senior Designer
    KCPQ, KMYQ & KRCW

  • Kevin Camp

    May 23, 2008 at 11:00 pm

    note… if this was all you wanted your script to do, you could save this as an animation preset and recall it from the animation presets when needed…

    to create the preset, select the layer with the expression, and select the parameter(s) (in this case just opacity) that you want include. then choose animation>save animation preset and give it a name (you can set/create a folder to keep things organized). presets are saved in the ae presests folder so you can easily move them to other systems (similar to scripts).

    preset are very useful and can be used to add multiple effects, settings, key framed data and expressions. the only limitation that they have is they can only effect a single layer… a preset cannot be made to effect multiple layers in different ways like a script can.

    Kevin Camp
    Senior Designer
    KCPQ, KMYQ & KRCW

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy