Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Filter out selected keyframes from one property

Explorer ,
Jun 14, 2022 Jun 14, 2022

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 🙂

TOPICS
How to , Resources , Scripting
453
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 3 Correct answers

Community Expert , Jun 14, 2022 Jun 14, 2022

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]);
}

 

Translate
Community Expert , Jun 14, 2022 Jun 14, 2022

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);
	}
}
Translate
Community Expert , Jun 15, 2022 Jun 15, 2022

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]));
}
Translate
Community Expert ,
Jun 14, 2022 Jun 14, 2022

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 14, 2022 Jun 14, 2022

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 14, 2022 Jun 14, 2022

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]);
}

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 14, 2022 Jun 14, 2022

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 14, 2022 Jun 14, 2022

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);
	}
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 15, 2022 Jun 15, 2022

Thank you

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 15, 2022 Jun 15, 2022

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 15, 2022 Jun 15, 2022
LATEST

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]));
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines