#!BPY

"""
Name: 'CG-Cam Exporter'
Blender: 245
Group: 'Export'
Tooltip: 'Exports the camera attributes, works only for one camera so far'
"""
import Blender
import bpy
import BPyMessages

def write(filename):
    if not BPyMessages.Warning_SaveOver(filename):
        return
    out = file(filename, "w")
    cam = bpy.data.objects["Camera"]
    position = cam.getLocation()
    rotation = cam.getMatrix()
    out.write(str(position[0]) + "\n")
    out.write(str(position[1]) + "\n")
    out.write(str(position[2]) + "\n")
   # out.write(str(rotation[0][0]) + "\n")
   # out.write(str(rotation[0][1]) + "\n")
   # out.write(str(rotation[0][2]) + "\n")
    out.write(str(rotation[1][0]) + "\n")
    out.write(str(rotation[1][1]) + "\n")
    out.write(str(rotation[1][2]) + "\n")	
    out.write(str(rotation[2][0]) + "\n")
    out.write(str(rotation[2][1]) + "\n")
    out.write(str(rotation[2][2]) + "\n")
    out.write("# Camera description file\n# Written by Nikolai Knopp\n" + 
    	"# From top to bottom, the lines contain X Y Z Coordinates," +
    	" then first,second,third row of Transformation Matrix");

Blender.Window.FileSelector(write, "Export", Blender.sys.makename(ext='.cam'))


