maya Python I want to fix the baked animation again.

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 ...

Command you want to make

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

The result of trial and error

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!

Brief commentary

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

maya Python I want to fix the baked animation again.
I want to display the progress in Python!
I want to inherit to the back with python dataclass
I want to write in Python! (3) Utilize the mock
I want to use the R dataset in python
I want to initialize if the value is empty (python)
[Python] I want to use the -h option with argparse
I want to know the features of Python and pip
I want to debug with Python
I want to know the weather with LINE bot feat.Heroku + Python
I want to output the beginning of the next month with Python
I want to run the Python GUI when starting Raspberry Pi
I want to pin Spyder to the taskbar
I want to output to the console coolly
I want to handle the rhyme part1
I want to handle the rhyme part3
I want to use jar from python
I want to build a Python environment
I want to analyze logs with Python
I want to play with aws with python
I want to display the progress bar
I want to handle the rhyme part2
I want to handle the rhyme part5
I want to handle the rhyme part4
(Python Selenium) I want to check the settings of the download destination of WebDriver
I want to batch convert the result of "string" .split () in Python
I want to explain the abstract class (ABCmeta) of Python in detail.
Python: I want to measure the processing time of a function neatly
I want to do Dunnett's test in Python
I want to use MATLAB feval with python
I want to memoize including Python keyword arguments
I want to create a window in Python
I want to email from Gmail using Python.
[Python] I want to manage 7DaysToDie from Discord! 1/3
I want to make a game with Python
I want to handle the rhyme part7 (BOW)
I want to merge nested dicts in Python
I want to use Temporary Directory with Python2
I want to use ceres solver from python
#Unresolved I want to compile gobject-introspection with Python3
I want to solve APG4b with Python (Chapter 2)
I want to sell Mercari by scraping python
[Python] I want to manage 7DaysToDie from Discord! 2/3
I want to make C ++ code from Python code!
[Python] I will upload the FTP to the FTP server.
I want to customize the appearance of zabbix
I want to write to a file with Python
I want to use the activation function Mish
[Python] I want to know the variables in the function when an error occurs!
I want to use Python in the environment of pyenv + pipenv on Windows 10
I want to crop the image along the contour instead of the rectangle [python OpenCV]
I want to get the file name, line number, and function name in Python 3.4
I want to write in Python! (1) Code format check
I want to see the file name from DataLoader
I tried to graph the packages installed in Python
I want to embed a variable in a Python string
I want to easily implement a timeout in python
I want to iterate a Python generator many times
I want to generate a UUID quickly (memorandum) ~ Python ~
I want to grep the execution result of strace
I want to scroll the Django shift table, but ...