FORUMS: list search recent posts

[solved] Script to duplicate a layer and insert it at the time of a keyframe value output

COW Forums : Adobe After Effects

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Dmitry Klingensmith
[solved] Script to duplicate a layer and insert it at the time of a keyframe value output
on Apr 12, 2017 at 4:23:44 pm
Last Edited By Dmitry Klingensmith on Apr 13, 2017 at 1:47:19 pm

I have a layer that has a radiowaves effect. I want that layer to do its effect at every point in time of a frequency output from soundkeys. I don't want to have to duplicate the layer and position it in the timeline manually at every keyframe of the soundkeys output expression value. How can i do this automatically with a script? I created one to show how to do this

Edit: I started creating the script. So far it just grabs keyframes and finds at what time the ones who's value is greater than a certain value. Duplicating and setting layers at those time values aren't finished yet. I had to copy the soundkeys output keyframes to a new layer's opacity property as i don't know how to grab the property called "Output 1".

Edit2: this is complete and i will be creating a UI for this with minor tweaks.

ar proj = app.project; // The Application Object is at the top level followed by the Project Object
var comp = proj.activeItem; // Set the comp variable to the active composition
var layer = comp.layer(1); // Set the layer variable to the first layer of the composition object
var Opacity = layer.Opacity; // Set the Opacity variable to the opacity property of the layer object
var numKeys = Opacity.numKeys; // Get the number of keyframes on the opacity property through the numKeys attribute
var Keyframe =[], KeyframeTime =[], KeyframeValue=[]; // Set empty variables for later assignment
var KeyCount = 0; //Count of keyframes over specific value

var KeyframeMin=[];
for(i=1; i<=numKeys; i++){ //keyframe index loop for the number of keyframe
Keyframe[i] = i; //indexes the number of keyframes
//alert ('keyframe ' + Keyframe[i] + ' done'); // Alert debug
}

if (numKeys > 0) {
for(i=1; i<=numKeys; i++){
KeyframeTime[i] = Opacity.keyTime(Keyframe[i]).toString(); // Get the keyframe time of Keyframe in seconds
KeyframeValue[i] = Opacity.keyValue(i).toString(); // Get the keyframe value of Keyframe
//alert('Keyframe of ' +Keyframe[i]+ ' is at time ' +KeyframeTime[i]+ ' and has a value of ' +KeyframeValue[i]); // Alert for debug
}

alert ('There are ' + numKeys + ' Keyframes'); // Alert for debug

} else {
alert ('There are no keyframes on this layer.'); // If there aren't any keyframes on the property of the layer then alert the user
}
var Min=1; //index start for select keframes once compared
for(i=1; i<=numKeys; i++){ //loops through number of keyframes
var MinkeyValue = 40; // key value to set as minimum
if(KeyframeValue[i] > MinkeyValue) { //if the value of the keyframe is less than 15
KeyframeMin[Min]=KeyframeTime[i]; //set that keyframe time to KeyframeMin array
KeyCount++; //counter for number of keyframes above minimum value
// alert('Keyframe ' +Keyframe[i] + ' found with time ' +KeyframeMin[Min]); //alert what keyframe # with it's value greater than 15
Min++; // increment index so it doesnt overwrite previous index value
}
}
alert('There are ' + KeyCount + ' keyframes greator than ' + MinkeyValue);
app.beginUndoGroup("Duplicated layers"); // Start of undo for duplication of layers
for(i=1; i<=KeyCount; i++){ // loops through the amount of keys above the min value
var index = (1+i); //index safegaurd to only copy the main layer
comp.layer(index).duplicate().startTime = KeyframeMin[i]; //duplicates layer and places it at the value of the array on the timeline
}
app.endUndoGroup(); // End of undo for duplication of layers



Return to posts index

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