Copy link to clipboard
Copied
Hi, everyone!
Is there a way to filter out selected keyframes from one property, like position or anchor point and change keys values? Also how do I check if the selected layers are part of these properties?
I would like to set the position of the anchor point to the selected keyframes.
Thank for answers 🙂
Here's a simple example that will set selected position keyframes (for layer 1) to [0,0]:
var myLayer = app.project.activeItem.layer(1);
var myProp = myLayer.property("Position");
var myKeys = myProp.selectedKeys;
for (var i = 0; i < myKeys.length; i++){
myProp.setValueAtKey(myKeys[i],[0,0]);
}
Something like this should work:
var myLayer = app.project.activeItem.layer(1);
var myProp = myLayer.property("Position");
if (myProp.numKeys > 0){
for (var i = 1; i <= myProp.numKeys; i++){
myProp.setSelectedAtKey(i, true);
}
}
Something like this, I think:
var myLayer = app.project.activeItem.layer(1);
var myAP = myLayer.property("Anchor Point");
var myPos = myLayer.property("Position");
var myKeys = myAP.selectedKeys;
for (var i = 0; i < myKeys.length; i++){
myPos.addKey(myAP.keyTime(myKeys[i]));
}
Copy link to clipboard
Copied
What do you mean by "filter out"? For a given property, scripting can detect which keyframes are selected, but it's not clear what you want to happen after that.
Copy link to clipboard
Copied
Thank you Dan for your response. I want to isolate selected keyframes that are part of a certain property like position or anchor point and perform actions on these keyframes, like setValueAtKey.
Copy link to clipboard
Copied
Here's a simple example that will set selected position keyframes (for layer 1) to [0,0]:
var myLayer = app.project.activeItem.layer(1);
var myProp = myLayer.property("Position");
var myKeys = myProp.selectedKeys;
for (var i = 0; i < myKeys.length; i++){
myProp.setValueAtKey(myKeys[i],[0,0]);
}
Copy link to clipboard
Copied
Hey Dan, thank you, this works perfectly. I'm still learning this language.
I'm also trying to understand how to check if there is a keyframe in a property, and if there is one, I would like to select all the keyframes in the property.
Copy link to clipboard
Copied
Something like this should work:
var myLayer = app.project.activeItem.layer(1);
var myProp = myLayer.property("Position");
if (myProp.numKeys > 0){
for (var i = 1; i <= myProp.numKeys; i++){
myProp.setSelectedAtKey(i, true);
}
}
Copy link to clipboard
Copied
Thank you
Copy link to clipboard
Copied
Thanks so much for the detail info Dan. Would it be also possible to assign new keyframes to position property at same time as selected keyframes from anchor point, without changing the value of position parameters, just add keyframes at same time as anchor point keyframes.
Copy link to clipboard
Copied
Something like this, I think:
var myLayer = app.project.activeItem.layer(1);
var myAP = myLayer.property("Anchor Point");
var myPos = myLayer.property("Position");
var myKeys = myAP.selectedKeys;
for (var i = 0; i < myKeys.length; i++){
myPos.addKey(myAP.keyTime(myKeys[i]));
}