Hello Everyone,

Here is a tool that it is WIP.  I know Maya has something already
similar to it however,  I figured it could be a good exercise for me
while I am learning python.


The issue that I am running into is, that  I only want one full curve
from the selected animated object however as you will see it creates a
curve on every frame.

import maya.cmds as cmds
"""

This tool creates a curve or multiple curves from an animated object's
translation.
Author:
    Martin LaLand Romero

"""

def main():
    """
    This function runs the genCurvefromObj function.
    """
    for i in genCurvefromObj(1, 95, 1):
        print(i)



    """
    This function generates a curve based on the object's animation
path.
    """
def genCurvefromObj(frameStart, frameStop, step):
    myObject = cmds.ls(selection = True)

    #This loop queries the position of the animated object and creates
a curve based on its position.
    for object in myObject:
        i = frameStart
        while i <=frameStop:
            yield i
            i += step
            print('The current frame is', cmds.currentTime( i, edit =
True))
            animationCurve = cmds.curve( p = [(0, 0, 0), (0, 0, 0),
(0, 0, 0), (0, 0, 0)], name = ('Jack_' + str(object) ))
            cmds.currentTime(i, edit = True)

            #Get the object position on everyFrame.
            pos = cmds.xform((object), r=True, query = True,  t=True )

            cmds.curve(animationCurve, append = True, p = pos,)
            cmds.delete(animationCurve + ".cv[0]")

if __name__ == "__main__": main()




Even after revising the loop as shown below, I am still just getting a
two point curve and a smooth curve.

frameStart = 1
frameStop = 100
step = 1

myObject = cmds.ls(selection = True)

    #This loop queries the position of the animated object and creates
a curve based on its position.
for object in myObject:
    i = frameStart
    while i <=frameStop:
        #yield i
        i += step
        print('The current frame is', cmds.currentTime( i, edit =
True))
    animationCurve = cmds.curve( p = [(0, 0, 0), (0, 0, 0), (0, 0,
0)], name = ('Jack_' + str(object) ))
    cmds.currentTime(i, edit = True)

    #Get the object position on everyFrame.
    pos = cmds.xform((object), r=True, query = True,  t=True )

cmds.curve(animationCurve, append = True, p = pos,)
cmds.delete(animationCurve + ".cv[0]")


Thank you guys,

Cheers
Martin

-- 
http://groups.google.com/group/python_inside_maya

Reply via email to