Copy link to clipboard
Copied
My problem:
My composition is i.e. 10 seconds long.
In this time I would like to have 10 keys.
The value will be defined later.
In my example the solution is easy.
But is there a function where I can define a number of keys, this function looks for the length of the composition, divides the length with the number of keys, and places the keys like this, that every key has exactly the same duration?
Copy link to clipboard
Copied
It could be scripted or one of those already existing scripts might come in handy:
Keyframes - Automation - After Effects - aescripts + aeplugins - aescripts.com
Mylenium
Copy link to clipboard
Copied
Lasergod schrieb:
But is there a function where I can define a number of keys, this function looks for the length of the composition, divides the length with the number of keys, and places the keys like this, that every key has exactly the same duration?
There is no ready to use function for this, but you can access the duration of a comp with
comp.duration // inherited from AVItem
and you can set keyframes for properties with
property.setValuesAtTimes(timesArray,valuesArray);
Hence, you can write such a function yourself.
Copy link to clipboard
Copied
This is a real basic setup that will add keys mathematically evenly to all selected properties that can vary over time, but not whole frame evenly. As in there could be a keyframe midway in a frame due to the math. More math would be needed to divide the keys on proper whole frames. It may get you started at least. Due to the non whole frame key locations you may get odd animation blips because of this, so use at your own risk.
var keyWin = new Window("dialog", "Type in desired key count.", undefined);
var et = keyWin.add("edittext", undefined, "");
et.alignment = ["fill", "top"];
var grp = keyWin.add("group", undefined);
grp.orientation = "row";
var go = grp.add("button", undefined, "Go");
go.onClick = function(){
var myComp = app.project.activeItem;
var compDur = myComp.duration;
var frameDur = myComp.frameDuration;
var maxFrames = (compDur / frameDur);
var etVal = Number(et.text);
var val = isNaN(etVal);
if(val == true){
alert("Please enter a number only");
}else{
if(maxFrames > etVal){
var myProps = myComp.selectedProperties;
var myPropsLen = myProps.length;
var intervalVal, curProp;
app.beginUndoGroup("Add keys");
for(var p=0; p<myPropsLen; p++){
curProp = myProps
;
if(curProp.canVaryOverTime == true){
intervalVal = compDur / etVal;
for(var k=0; k<etVal; k++){
curProp.addKey(intervalVal*k);
}
}
}
app.endUndoGroup();
}else{
alert("Error:\nThat many keys exceeds the current timeline max of " + maxFrames.toString() + " frames.\n\nPlease choose a value lower than " + maxFrames.toString() + ".");
}
}
};
var close = grp.add("button", undefined, "close");
close.onClick = function(){keyWin.close();};
keyWin.center();
keyWin.show();