zaidi92 zaidi92 - 1 year ago 67
Python Question

Need help creating curves based on set keyframe positions (maya/python)

I'm trying to create a tool in maya using python that creates curves based on an objects keyframe positions. The end goal is to create different animation curves that the object can blend between so as to create adjustments to the main animation. Here's what I have so far. It creates a curve that follows the path of motion but it's not based on keyframe position. Any help would be really appreciated.

import maya.cmds as cmds

def createAnimCurve( startFrame, endFrame, numCV, object ):
curveCVstep = ((endFrame - startFrame)+startFrame)/numCV
points = []
for step in range( startFrame, endFrame, int(curveCVstep)):
# Moves throughout the specified timeline to find point results
cmds.currentTime( step )
# Queries the pivot position to draw the curve relative to the controller
xpos = cmds.xform( object,q=1,ws=1,rp=1 )
# convert the tuple (vector) to a string
cmds.curve(d=3, ws=True, p=points, n=object+'_xPath')


Answer Source

If I understand you correctly, you'll want to iterate through key frames (using keyframe timeChange query) rather than a start/end range stepping numCvs.

keyframes = sorted(list(set(cmds.keyframe(object, q=True, timeChange=True))))

Also, avoid using object as a variable name it's a built-in.