I just tried to make something like this for studying maya and python.
First, create a simple IK animation Set the key to iKHandle1 in the 1st, 5th, and 10th frames Like this ...
Bake the animation round Then, keys are struck in all frames like this in Joint etc.
I want to delete only 1 5 10 keyframes from here. I want to change the animation so that it is difficult to correct because all the keys are hit wherever it is. I wonder if that mean. I just need to save it with a different name before baking ...
procedure Create one cube etc. and set keys in 1,5,10 frames. After that, first select the cube, then select the baked object and execute the command! Ideal result Animations other than the keys set in the cube are deleted
I managed to do it
import maya.cmds;
model = cmds.ls(selection=True)[0];
keyTimes = cmds.keyframe(model,query=True);
timeList = range(1, int(max(keyTimes)));
data = list(set(timeList) - set(keyTimes));
selectObjList = cmds.ls(selection=True);
for frameTime in data:
for obj in selectObjList[1:]:
cmds.cutKey(obj, time=(frameTime,frameTime), cl=1);
It's unpleasant to write if you can't become python, but it's short!
Set the name of the first selected object to model
model = cmds.ls(selection=True)[0];
Get the keyframe of the first selected object (there is a duplicate because we have all)
keyTimes = cmds.keyframe(model,query=True)
Create a list of frame numbers up to the maximum time (in this case, 1,2,3,4,5,6,7,8,9,10)
timeList = range(1, int(max(keyTimes)));
Get keyframe diff (list of keyframes to erase) (2,3,4,7,8,9)
data = list(set(timeList) - set(keyTimes))
After that, loop around with the selected object (except the first one), In addition, loop around with the list of keyframes to delete, OK with cutKey!
selectObjList = cmds.ls(selection=True);
for frameTime in data:
for obj in selectObjList[1:]:
cmds.cutKey(obj, time=(frameTime,frameTime), cl=1);
Recommended Posts