Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects ExtendScript, How to add opacity keyframe to any selected layer at current time?

  • ExtendScript, How to add opacity keyframe to any selected layer at current time?

    Posted by Mohd Faizan on October 13, 2020 at 7:31 pm

    This is what I tried, but not working :/

    var myLayer = app.project.item(index).layer(index).propertySpec;
    var myProperty = myLayer.opacity;
    myProperty.setValue(50);

    Mohd Faizan replied 5 years, 7 months ago 2 Members · 3 Replies
  • 3 Replies
  • Walter Soyka

    October 13, 2020 at 7:49 pm

    You don’t need the .propertySpec business, and if you want to add keyframes, you need to uset setValueAtTime(). Here’s some sample code to set an opacity keyframe at 50% on the first layer of the first item in the project at its current time:

    var myLayer = app.project.item(1).layer(1);
    var myProperty = myLayer.opacity;
    myProperty.setValueAtTime(myLayer.containingComp.time, 50);

  • Mohd Faizan

    October 13, 2020 at 7:59 pm

    Thankyou so much!
    It is working fine for 1st layer, but I wanted it to applied on selected layer(s).

  • Mohd Faizan

    October 13, 2020 at 8:25 pm
    var myLayers = app.project.activeItem.selectedLayers;
    if (myLayers.length > 0) {
    for (var i = 0; i < myLayers.length; i++) {
    var myProperty = myLayers[i].opacity;
    myProperty.setValueAtTime(myLayers[i].containingComp.time, 0);}
    } else {alert("No layers selected.");}

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