Fade in and out help

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
untruehero
Posts: 2
Joined: May 23rd, 2008, 8:15 am

Hello,

I'm new to AE scripts and I really never knew they existed until recently. I have written AS and I know it's different but I understand it. I'm trying to write a basic script that would allow me to run it and add 2 keyframes. One at the current location in the layer that is selected and one that is 15 frame down. The first keyframe would be 0% and the second would be 100%. And then the opposite would apply for the end of the layer. This is something basic but it would make production go a bit faster.

Can someone please give me a hand, I would like to learn how to write it myself but the resources on AE scripting are limited at best. I tried the help menu in ExtendScript but I can't really find the values and methods I'm looking for.

Thanks!
untruehero
Posts: 2
Joined: May 23rd, 2008, 8:15 am

Well I figured out how to add opacity keyframes. But I can only add it to the a specific layer and at a certain time. I would like to add it at the current position and base it on frames instead of seconds.

Is there any way to make the code specify the current layer and not the number layered that I pick. Alsocan the setValueAt Time code use frames instead of seconds?

Code: Select all

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

myOpacity.setValueAtTime(0, 0);
myOpacity.setValueAtTime(1/2, 100);
Any help would be great.
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

myComp.selectedLayers will return an array of selected layers which you can loop through.
You can multiply by myComp.frameDuration to convert frames into seconds.
I've used myComp.time to get the current time for the first keyframe, and each layer's outPoint for the last key.

Paul

Code: Select all

var frameOffset = 10;
var myComp = app.project.activeItem;
var offsetInSecs = frameOffset * myComp.frameDuration;
var selectedLayers = myComp.selectedLayers;

for (var i = 0; i < selectedLayers.length; i++) {
	myOpacity = selectedLayers[i].property("opacity");
	myOpacity.setValueAtTime(myComp.time, 0);
	myOpacity.setValueAtTime(myComp.time + offsetInSecs, 100);
	myOpacity.setValueAtTime(selectedLayers[i].outPoint - offsetInSecs, 100);
	myOpacity.setValueAtTime(selectedLayers[i].outPoint, 0);
	
}
Post Reply