Search code examples
pythoncameramayaautodesknuke

Python : export keyframe from maya in line


I am trying to make a script that writes all the desired parameters in a line, not in row, to make a pipe to nuke (keyframe in line) to be valid in nuke, Keyframe need to be like this

translate {{curve R x1 list of valueX}} {curve R x1 list of valueY}} {curve R x1 list of valueZ}}

example

translate {{curve R x1 10 11.03448296 12.06896591 13.10344791 14.13793087 15.17241383} {curve R x1 20 22.06896591 24.13793182 26.20689583 28.27586174 30.34482765} {curve R x1 30 33.10344696 36.20689774 39.3103447 42.41379166 45.51724243}}

For now i'm able to extract value from attribute i want but it result in column and, when i put several commands, it return and error

def convert():
    print "Loading file: "

    # Select the incoming tracked camera
    cmds.select('Camera0Node', r=1)

    # Get first and last key set to determine bake range
    firstKey = int(cmds.findKeyframe(time=(0, 100000), which='first'))
    lastKey = int(cmds.findKeyframe(time=(0, 100000), which='last')) 
    print "Frame range: [", int(firstKey), ":", int(lastKey), "]"

    # Enable depth of field
    tx = cmds.getAttr(".tx")
    ty = cmds.getAttr(".ty")
    tz = cmds.getAttr(".tz")
    rx = cmds.getAttr(".rx")
    ry = cmds.getAttr(".ry")
    rz = cmds.getAttr(".rz")
    hfa = cmds.getAttr('.horizontalFilmAperture')
    vfa = cmds.getAttr('.verticalFilmAperture')
    fl = cmds.getAttr('.focalLength')
    vfov = 2 * (math.atan2(vfa/2.0*25.4,fl) * 180 / math.pi);

    # Bake out to Euler angles
    cmds.bakeResults('Camera0Node',sparseAnimCurveBake=False, minimizeRotation=True, removeBakedAttributeFromLayer=False, removeBakedAnimFromLayer=False, oversamplingRate=1, bakeOnOverrideLayer=False, preserveOutsideKeys=False, simulation=True, sampleBy=1, shape=True, t=(firstKey, lastKey), disableImplicitControl=True, controlPoints=False)
    print str(tx)

convert()

return

Loading file: 
Frame range: [ 1 : 504 ]
2385.11

So i only have one value of x, How can i get all keyframe value and format it the nuke way ?

thank you


Solution

  • I've found the answer:

    keyframe -q -vc Camera0Node.translateX
    

    You gave me exactly what I needed.

    Thank you.