Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions scripting question…

  • scripting question…

    Posted by Danny Princz on September 25, 2006 at 7:22 pm

    i have a comp that im wokring with that id like to script the following.

    i have many layers lets call them, layer1, layer1_active, layer2, layer2_active, layer3, layer3_active, etc.

    im trying to write a script that when i select a layer, lets say layer1, i can run the script that for this example would apply some opacity keyframes, say, 100% 5 frames b4 the current time, 50% at the current time, 50% 5 frames later, etc.
    i understand the setValuesAtTimes, i just dont know how to get the current time to be a variable.

    how do i get the current comp time in the script?

    and then second.

    say the selected layer is layer1, then apply keyframes in a similayer manner to the layer1_active, ie the another layer that has the selecteds name plus a suffix?

    any ideas?

    Danny Princz replied 19 years, 7 months ago 2 Members · 7 Replies
  • 7 Replies
  • Dan Ebberts

    September 25, 2006 at 8:16 pm

    I think you get the layer time like this:

    var myComp = app.project.activeItem;
    var myLayer = myComp.selectedLayers[0];
    var myCurrTime = myLayer.time;

    and do this to get the layer with the suffix:

    var suffix = “_active”;
    var myNewLayer = myComp.layer(myLayer.name + suffix);

    Not tested, but should be close.

    Dan

  • Danny Princz

    September 25, 2006 at 8:38 pm

    thanks dan

    i was trying something like that for the time but couldnt get it to work.

    ill give it another go

  • Danny Princz

    September 25, 2006 at 8:45 pm

    it must be somthing else i am doing wrong as that is pretty much what i had

    i am an error that the value is not a float

    heres a test script

    var myComp = app.project.activeItem;
    var myLayer = myComp.selectedLayers[0];
    var myCurrTime = myLayer.Time;
    keyTimes = new Array (1,2,myCurrTime);
    keyValues = new Array(10,20,30);
    myLayer.opacity.setValuesAtTimes(keyTimes,keyValues);

  • Dan Ebberts

    September 25, 2006 at 11:30 pm

    You just need to change:

    myLayer.Time;

    to:

    myLayer.time;

    Dan

  • Danny Princz

    September 26, 2006 at 2:38 pm

    ugh

    thanks so much

    i couldnt figure out why it wasnt working…

    i also have a layer expression effect that i would like to use to choose the layer that the script targets but i cant get that to work either.

    if i have an effect on myLayer named chooser

    var myTarget = myLayer.effect(“chooser)(“Layer”)

    so

    var myComp = app.project.activeItem;
    var myLayer = myComp.selectedLayers[0];
    var myCurrTime = myLayer.time;
    keyTimes = new Array (1,2,myCurrTime);
    keyValues = new Array(10,20,30);
    var myTarget = myLayer.effect(“chooser”)(“Layer”);

    myTarget.opacity.setValuesAtTimes(keyTimes,keyValues);

    what am i doing wrong here?

    thanks again

  • Dan Ebberts

    September 26, 2006 at 3:13 pm

    This seems to work:

    var myComp = app.project.activeItem;
    var myLayer = myComp.selectedLayers[0];
    var myCurrTime = myLayer.time;
    keyTimes = new Array (1,2,myCurrTime);
    keyValues = new Array(10,20,30);
    var myTarget = myComp.layer(myLayer.effect(“chooser”)(“Layer”).value);
    myTarget.opacity.setValuesAtTimes(keyTimes,keyValues);

    Dan

  • Danny Princz

    September 26, 2006 at 3:39 pm

    .value

    awesome

    thanks so much

    you are the man!

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