Importing chan camera into Maya

I am trying to import this camera animation information which was initially a .chan format from Nuke and imparts the information into the Maya camera, thus meaning to say, the Maya camera will works the same way as the one in the Nuke.

Currently I am having trouble to imports in the values of the nuke camera into maya camera. The following is importing dialog:

filters = "chan (*.chan)"
fileList = cmds.fileDialog2(fileMode=1, fileFilter=filters, dialogStyle=2)

with open (fileList[0], 'rt') as filehandle:
     for line in filehandle:
         print line

And this will displays the output aka. the information in the .chan file. It is following in this order: Frame, translateX, translateY, translateZ, rotateX, rotateY, rotateZ.
A small snippet of the output is as follows:

1	0	0	0	180	-0	0	39.2164

2	0.763887	0.0190331	-0.0218766	-178.268	-5.44147	-0.346042	39.2164

3	5.92473	0.344456	6.6543	17.5934	-74.886	168.27	39.2164

4	6.11879	0.30712	5.50863	79.2254	-87.0982	104.943	39.2164

I have tried changing my code in the latter part into this:

with open (fileList[0], 'rt') as filehandle:
    rows = zip(*[line.split() for line in filehandle])

This is so that it will make ‘group’ the frames as well as both the translation and rotation values indivually for an ease of access.

However, if I tried to incorporate it into different functions for the frames and the trans/rot. values, I will be getting errors as follows:

cmds.currentTime(int(rows[0]), edit=True, update=False)
cmds.setKeyframe("camera1", attribute='translateX', v=float(row[1]))

# Error: float() argument must be a string or a number
# Traceback (most recent call last):
#   File "<maya console>", line 1, in <module>
# TypeError: float() argument must be a string or a number # 

Or there are times, it sort of worked but it is only keying in the animation at the last frame.

Perhaps are there any better ways to handle this?

Anyone?

The way you are doing it now “rows” is a list of tuples which looks like this:


[('1', '2', '3', '4'), ('0', '0.763887', '5.92473', '6.11879'), ('0', '0.0190331', '0.344456', '0.30712'), ('0', '-0.0218766', '6.6543', '5.50863'), ('180', '-178.268', '17.5934', '79.2254'), ('-0', '-5.44147', '-74.886', '-87.0982'), ('0', '-0.346042', '168.27', '104.943'), ('39.2164', '39.2164', '39.2164', '39.2164')]

So you’re getting the TypeError because you’re using float() on a tuple instead of a string. I’m not sure how you were intending to format that data (the way it is now does not seem optimal to me) but it isn’t doing what you expected it to do.

Maybe something like this would be simpler?:


with open (fpath, 'rt') as filehandle:
    for line in filehandle:
        rowValues = line.split()
        
        frameNumber = int(rowValues[0])
        translation = (float(rowValues[1]), float(rowValues[2]), float(rowValues[3]))
        rotation = (float(rowValues[4]), float(rowValues[5]), float(rowValues[6]))
        
        print "frameNumber = %s" % frameNumber
        print "translation = %s" % str(translation)
        print "rotation = %s" % str(rotation)

[QUOTE=Warheart;25459]The way you are doing it now “rows” is a list of tuples which looks like this:


[('1', '2', '3', '4'), ('0', '0.763887', '5.92473', '6.11879'), ('0', '0.0190331', '0.344456', '0.30712'), ('0', '-0.0218766', '6.6543', '5.50863'), ('180', '-178.268', '17.5934', '79.2254'), ('-0', '-5.44147', '-74.886', '-87.0982'), ('0', '-0.346042', '168.27', '104.943'), ('39.2164', '39.2164', '39.2164', '39.2164')]

So you’re getting the TypeError because you’re using float() on a tuple instead of a string. I’m not sure how you were intending to format that data (the way it is now does not seem optimal to me) but it isn’t doing what you expected it to do.

Maybe something like this would be simpler?:


with open (fpath, 'rt') as filehandle:
    for line in filehandle:
        rowValues = line.split()
        
        frameNumber = int(rowValues[0])
        translation = (float(rowValues[1]), float(rowValues[2]), float(rowValues[3]))
        rotation = (float(rowValues[4]), float(rowValues[5]), float(rowValues[6]))
        
        print "frameNumber = %s" % frameNumber
        print "translation = %s" % str(translation)
        print "rotation = %s" % str(rotation)

[/QUOTE]

I used float as you can see in my list, there are tons of them which are in decimal values, and I had wanted to capture such info to the best if possible.

As in the end of the day, I am going to use the said values and insert them into maya commands such as cmds.keyframe etc, mapping them on the camera so that it is moving precisely in the same manner as it was in Nuke…

Converting to floats is fine. There’s nothing wrong with doing that.

The problem in your code is when you do:

float(row[1])

That gives you an error because row[1] refers to a tuple of strings not just one string. In other words, the float() function can’t convert a tuple into a float.

Here’s an updated example to show how you could make use of the values:


myCamera = "camera1"
with open (fpath, 'rt') as filehandle:
    for line in filehandle:
        rowValues = line.split()
        
        frameNumber = int(rowValues[0])
        translation = (float(rowValues[1]), float(rowValues[2]), float(rowValues[3]))
        rotation = (float(rowValues[4]), float(rowValues[5]), float(rowValues[6]))
        
        cmds.currentTime(frameNumber)
        cmds.setKeyframe(myCamera, attribute='translateX', v=translation[0])
        cmds.setKeyframe(myCamera, attribute='translateY', v=translation[1])
        cmds.setKeyframe(myCamera, attribute='translateZ', v=translation[2])
        cmds.setKeyframe(myCamera, attribute='rotateX', v=rotation[0])
        cmds.setKeyframe(myCamera, attribute='rotateY', v=rotation[1])
        cmds.setKeyframe(myCamera, attribute='rotateZ', v=rotation[2])

[QUOTE=Warheart;25461]Converting to floats is fine. There’s nothing wrong with doing that.

The problem in your code is when you do:

float(row[1])

That gives you an error because row[1] refers to a tuple of strings not just one string. In other words, the float() function can’t convert a tuple into a float.

Here’s an updated example to show how you could make use of the values:


myCamera = "camera1"
with open (fpath, 'rt') as filehandle:
    for line in filehandle:
        rowValues = line.split()
        
        frameNumber = int(rowValues[0])
        translation = (float(rowValues[1]), float(rowValues[2]), float(rowValues[3]))
        rotation = (float(rowValues[4]), float(rowValues[5]), float(rowValues[6]))
        
        cmds.currentTime(frameNumber)
        cmds.setKeyframe(myCamera, attribute='translateX', v=translation[0])
        cmds.setKeyframe(myCamera, attribute='translateY', v=translation[1])
        cmds.setKeyframe(myCamera, attribute='translateZ', v=translation[2])
        cmds.setKeyframe(myCamera, attribute='rotateX', v=rotation[0])
        cmds.setKeyframe(myCamera, attribute='rotateY', v=rotation[1])
        cmds.setKeyframe(myCamera, attribute='rotateZ', v=rotation[2])

[/QUOTE]

Hi Warheart, thanks and sorry for my late reply.

Having used your code, it is working towards my cause. Now I think I will need to find some other ways that it can read the aperture values that was used in this .chan file and have it translated so that it can also be used in Maya (pretty far-fetched though, seeing that there isn’t much of any ways to do it using maya.cmds :()