Hello Everyone,

I am currently working on a basic tool, it is WIP. The purpose of the
tool is to create a curve from an object's translation.  I know that
Maya has something like this already however, I wanted to create the
actual script myself using Python.

I have a problem with the script, it seems to be creating a curve at
every frame instead of creating one whole curve drawing the whole
path, any hints?

Thanks so much!

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, the tool still doesn't
work.


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