Deselect key of the current frame located on the timeline

Deselect key of the current frame located on the timeline

dg3duy
Collaborator Collaborator
396 Views
4 Replies
Message 1 of 5

Deselect key of the current frame located on the timeline

dg3duy
Collaborator
Collaborator

Of the keys that are selected, deselect only those that are in the current animation frame.

The code selects the current key and one before and one after the current time, I just need to deselect the one that is currently located on the timeline and I don't know how to do it.

Here is a video example of how I want it to be deselected.

keyA = mc.currentTime(q = True)
ttA = mc.findKeyframe(t = (keyA,keyA), w = "previous")
ttB = mc.findKeyframe(t = (keyA,keyA), w = "next")

cmds.selectKey(animation='objects',add=False,t=(ttA,ttB))   


keys deselected.gif

0 Likes
Accepted solutions (1)
397 Views
4 Replies
Replies (4)
Message 2 of 5

Kahylan
Advisor
Advisor

Hi!

 

You already have all the commands you need and a variable for the time you need. All you need to do is switch some flags. In cases like this, just looking up the documentation on the commands you use can help you figure stuff like this out by yourself.

 

https://help.autodesk.com/cloudhelp/2022/ENU/Maya-Tech-Docs/CommandsPython/selectKey.html

https://help.autodesk.com/cloudhelp/2022/ENU/Maya-Tech-Docs/CommandsPython/findKeyframe.html

https://help.autodesk.com/cloudhelp/2022/ENU/Maya-Tech-Docs/CommandsPython/currentTime.html

 

This is how the code you are looking for looks like when you are finished.

import maya.cmds as mc

keyA = mc.currentTime(q = True)
mc.selectKey(animation = 'objects', k = True,time = (keyA,keyA), rm = True)

 

I hope it helps!

 

Message 3 of 5

dg3duy
Collaborator
Collaborator

This is exactly what I was looking for! thank you very much, it is very helpful.🤗

Before I finish the topic and accepted the solution I have a question that is related to this, and if the result that is seen on the screen the key selection I want to add the next key and the following key to the already selected?
keys unselect.gif

0 Likes
Message 4 of 5

Kahylan
Advisor
Advisor
Accepted solution
import maya.cmds as mc

curves = mc.keyframe(q= True, n = True)

for c in curves:
    
    kf = mc.keyframe(c,q= True, selected = True)
    prev = mc.findKeyframe(c,t = (kf[0],kf[0]), w= "previous")
    next = mc.findKeyframe(c,t = (kf[-1],kf[-1]), w= "next")
    mc.selectKey(c, t =(prev,prev), add= True)
    mc.selectKey(c, t =(next,next), add= True)
    
Message 5 of 5

dg3duy
Collaborator
Collaborator

Without words, a great gesture to give me the solution to the problem, and not only that, the explanation and the clarity of the script make me learn at the same time.

0 Likes