Python / Maya .write question

I am trying to write out attribute values from maya nodes to a text file. I have this working almost. I just need to know how to write a list of values to the file. I get the following error:

# Error: argument 1 must be string or read-only character buffer, not list

Here is the code:

Code:

    import maya.cmds as mc
   
    myFileObject=open('/data/keyFrames.txt', 'w')
   
    obs = mc.ls(sl=True)
    myY = []
 
    for selection in obs:
        myAtF = mc.getAttr(selection + '.ty')
        myAt = str(myAtF)
        myY.append(myAt +'\n')
       
    myFileObject.write(myY)
    myFileObject.close()


I guess the problem lies here:

Code:

myFileObject.write(myY)


I need to know how to convert myY ([‘1.32054365278\n’, ‘9.59632723791\n’, ‘5.49012983596\n’]), which is a list, to a string?

What I am trying to end up with raw values, formatted like below, in a text file.

1.32054365278
9.59632723791
5.49012983596

These are the y translate values of three selected spheres, just for example.

No Responses to “Python / Maya .write question”

Post a Comment