-
remove keys on property A except where property B has keys
Hello,
I am new to this forum and to scripting, so nice to meet you and sorry for my “noobism”
For my first script, I am trying to delete all keys from property A (which has keys on every frame), except where property B has keys (not necissarely on every frame).
My strategy :
1. get times of BProp keys
2. delete keys on AProp except at times retrieved in 1.I think step 1 is OK, I followed a tutorial and can see that the function returns the correct times.
Things get wierd in step 2. I’ve tweaked all parts of the code and got all kinds of results, including the exact opposite of what I want (delete Akeys at Btimes), but can’t get it to work correctly… Might be a mixup of key indexes/ comp frame time, or a problem with the nested for loops…Here’s a basic version of the setup… Doesn’t work at all, but shows the strategy.
Any help appreciated !
Thanks 😉// create an undo group
app.beginUndoGroup("S_RemoveKeys");var AProp = app.project.item(1).layer("Shape Layer 1").property("Contents").property("Group 1").property("Contents").property("Path 1").property("Path");
var BProp = app.project.item(1).layer("KeyLayer Comp 1").property("Time Remap");var BKeyTimes = getKeyTimes(BProp);
var ALen = AProp.numKeys;
var FramesTime = ALen-1
var BLen = BProp.numKeys;
CurItem.layers.addText(FramesTime.toString());for (var t = FramesTime; t>0; --t) { // for t = every frame (= Akeys index - 1)
var e = t+1; // e = AKey index at time "t"
for(var i = BLen; i>=0;--i) { // for i = every index of "BKeyTimes" Array
if (t = BKeyTimes[i]) { // check if "t" is in "BKeyTimes" Array
}else{
AProp.removeKey(e); // if "t" is not in "BKeyTimes" Array, delete key
}
}
}function getKeyTimes(prop) {
var KeyTimes = new Array();
var KeysLen = prop.numKeys;for(var k =1; k<=KeysLen; k++) { // for k = every key index
var q = prop.keyTime(k)*25 // get "prop" key times, multiply by framerate(25) to get times in frames
KeyTimes.push(q); // add to "KeyTimes" Array
}
return KeyTimes;
}// close the undo group
app.endUndoGroup();