Created
October 6, 2011 20:10
-
-
Save johnpneumann/1268508 to your computer and use it in GitHub Desktop.
Get animation data from a selected object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
@author: | |
John P. Neumann | |
@applications: | |
Maya | |
@description: | |
Needed to get animation data from an object that was being driven | |
via animation nodes so I scripted this real quick. It should put | |
the file into your home directory named keydata.txt, which you can | |
then pull into a script or whatever you wanna do. | |
""" | |
import os, sys | |
def get_key_data(path, objects): | |
""" | |
get_key_data is a function that gets key data and writes | |
it out to a file. | |
@type path: str | |
@param path: The path to the directory to write out to. | |
@type objects: list | |
@param objects: List of objects to write out the keydata for. | |
""" | |
if not os.path.exists(path): | |
sys.stderr.write('Path "%s" does not exist!!!' % (path)) | |
return False | |
if isinstance(objects, str): | |
new_obj = objects | |
objects.append(new_obj) | |
for obj in objects: | |
dkey = [] | |
key_data = cmds.keyframe(obj, q=True, vc=True) | |
time_data = cmds.keyframe(obj, q=True, tc=True) | |
for num, data in enumerate(key_data): | |
dkey.append([time_data[num], data]) | |
full_path = os.path.join(path, obj) | |
f = open(full_path, 'w') | |
for key in dkey: | |
f.write('%s,\n' % (key)) | |
f.close() | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment