I'm trying to make a script to delete the keys before and after on my current selected key. I'm not good enough in python scripts. but I tried this. But Sadly its failed. can any one help me out to fix this.
cmds.cutKey(‘pSphere1_translateX’, clear=1, time=(2, 300))
What i want?
Suppose I'm on key frame 20, then i want to delete 5 keys before and after from current(20) keyframe.
First query the time values of your keyframes.
Find the index of the current frame.
Then construct your cutKey command to remove 5 indices before and after the current index. I can't remember but you may be able to define more than one index range. I'm pretty sure you can. Otherwise, once you cut the first index range, you'd need to update the post index range since it will be different after removing the pre index range.
Hi,
Can you please elaborate with formula here as example. So I could understand visually here..
Thanks a lot for reply here.
To get the frames of your animation curve:
float $frames[] = `keyframe -q -tc "your_anim_curve"`;
Now let's say your current frame is 100. Loop through the $frames array to find which index is "100".
int $currentFrameIndex;
for($i=0;$i<size($frames);$i++)
{
if($frames[$i] == 100)
{
$currentFrameIndex = $i;
break;
}
}
Now you can cut the keys you want. 5 frames fore and aft.
cutKey -index (($currentFrameIndex-5)+":"+($currentFrameIndex-1))
That will cut the 5 frames before your current frame. Of course, you need the rest of the cutKey command options to finish that command.
Now that you have deleted those frames, the $currentFrameIndex is no longer relevant. So you need to update it. It has shifted 5 indices forward.
$currentFrameIndex -= 5;
Now construct the cutKey command for the aft 5 frames.
cutKey -index (($currentFrameIndex+1)+":"+($currentFrameIndex+5))
I'm typing this here without testing this in Maya. But that is the general idea.
Sorry, I just realized you did your code in Python. But it's pretty straightforward to convert MEL to Python. Let me know if you have any issues.
Can't find what you're looking for? Ask the community or share your knowledge.