ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Using frames instead of seconds in a script

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Sam Lanes
Using frames instead of seconds in a script
on Jan 24, 2020 at 9:20:45 am

I am currently writing a simple script that allows me to set a series of keyframes along a layer's opacity.

I have managed to get this to work, but the code is currently only working in seconds (which is where I have just put the second and third keyframes 0.1 and 0.2 seconds further along.

This works, but I am wondering if it is possible to make the script refer to frames, so that I can be more accurate with the placement? Usually, I place three keyframes in place, 2 frames apart, and this is what I would like to replicate, if possible.

var ActiveComp = app.project.activeItem;
var selectedLayers = ActiveComp.selectedLayers;
var numLayers = selectedLayers.length;
var currentTime = selectedLayers.time;
var time = app.project.activeItem.layer(1).time;



if(numLayers == 0){
alert("Select a layer");
} else {
selectedLayers[0].property("ADBE Transform Group").property("ADBE Opacity").setValueAtTime(time,100);
selectedLayers[0].property("ADBE Transform Group").property("ADBE Opacity").setValueAtTime(time+0.1,0);
selectedLayers[0].property("ADBE Transform Group").property("ADBE Opacity").setValueAtTime(time+0.2,100);
};


Return to posts index

Andrei Popa
Re: Using frames instead of seconds in a script
on Jan 24, 2020 at 1:18:40 pm

comp.frameDuration is how long a frame is. Basically time = 2*comp.frameDuration means second frame.

var ActiveComp = app.project.activeItem;
var frameDuration = ActiveComp.frameDuration;
var selectedLayers = ActiveComp.selectedLayers;
var numLayers = selectedLayers.length;
var currentTime = selectedLayers.time;
var time = app.project.activeItem.layer(1).time *ActiveComp.frameDuration; ;



if(numLayers == 0){
alert("Select a layer");
} else {
selectedLayers[0].property("ADBE Transform Group").property("ADBE Opacity").setValueAtTime(time,100);
selectedLayers[0].property("ADBE Transform Group").property("ADBE Opacity").setValueAtTime(time+2*frameDuration,0);
selectedLayers[0].property("ADBE Transform Group").property("ADBE Opacity").setValueAtTime(time+4*frameDuration,100);
};


Andrei
My Envato portfolio.


Return to posts index

Sam Lanes
Re: Using frames instead of seconds in a script
on Jan 24, 2020 at 2:44:30 pm

Thanks Andrei - the frameDuration element is what I didn't know! That works great.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2020 CreativeCOW.net All Rights Reserved
[TOP]