Skip to content

Instantly share code, notes, and snippets.

@johnpneumann
Created April 2, 2012 19:50
Show Gist options
  • Save johnpneumann/2286761 to your computer and use it in GitHub Desktop.
Save johnpneumann/2286761 to your computer and use it in GitHub Desktop.
Write out clip file for Houdini from Maya
"""
@author:
John P. Neumann (aka ArrantSquid)
@description:
Writes out a clip file (for use in Houdini) based on maya attributes
passed in.
@usage:
main('some_object', ['scaleX','visibility'], 'some_dir')
main('some_object', ['translate'], 'some_dir')
"""
import os
import sys
from maya import cmds
def main(obj, channel, frame_rate, output_dir):
"""
gets an objects channel data and outputs it to a clip file.
@type obj: str
@param obj: The object we want the data for
(eg. someCharacter:MoveScaleRotate")
@type channel: list
@param channel: List of attributes we want the data for.
@type frame_rate: float
@param frame_rate: The frame rate you wish to export at.
(eg. 24.0 - film, 29.97 - ntsc)
@type output_dir: str
@param output_dir: The directory we want to output the data to.
@rtype: bool
@returns: True or False.
"""
start_frame = cmds.playbackOptions(q=True, ast=True)
end_frame = cmds.playbackOptions(q=True, aet=True)
if isinstance(channel, str):
tmp_chan = channel
channel = []
channel.append(tmp_chan)
if ':' in obj:
obj_name= obj.split(':')[0]
else:
obj_name= obj
out_file = os.path.join(output_dir, '%s.clip' % (obj_name))
try:
fopen = open(out_file, 'w')
except IOError, err:
msg = ('Error opening file %s\nError: %s\n' % (out_file, err))
sys.stderr.write(msg)
return False
tracks = len(channel)
fopen.write('{\n')
fopen.write('\trate = %.02f\n' % (frame_rate))
fopen.write('\tstart = %d\n' % (start_frame))
fopen.write('\ttracklength = %d\n' % (end_frame))
fopen.write('\ttracks = %d\n' % (tracks))
for chan in channel:
key_data = cmds.keyframe('%s.%s' % (obj, chan),
t=(start_frame, end_frame),
vc=True, q=True)
fopen.write('\t{\n')
fopen.write('\t\tname = %s\n' % (chan))
fopen.write('\t\tdata = %s\n' % (' '.join(map(str, key_data))))
fopen.write('\t}\n')
fopen.write('}\n')
fopen.close()
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment