A simple BVH export for selected object

Here is a script I made primarily to match camera motion in Blender and Cinema4D, Others may find it useful. C4D has a Y up coord sys, so I had to mix up the XYZs to get it to look right in C4D. Also had to scale all my Loc values up by 100 times. Hopefully someone else can make use of it.

It has no Gui and is a bit tricky but does the job.

#######################################
# Blend2BVH for C4D Ver1
# by mthoenes
#
# This is a simple export of position and rotation
# to a BVH file for a selected object. This script 
# works for objects that are keyed, not for objects
# moving due to the translation/rotation of parent or
# path influence.
#
# I wrote this script to transfer camera and object motion info to
# Cinema4D. Cinema4D has a Y up coord system so I have had to 
# crossconnect the XYZs.
#
# Althought this script works for me, It could use improvement
# You are welcome to use and modify/improve the script, and
# make it your own.
# 
# Instructions
# 1. Load script in Text Window
# 2. Link Script to Selected object on FrameChanged
# 3. Enter value for Frames and Frame Time below,
#    frametime is 1/fps for example 30fs is .03333, 25 is .04
# 4. Set path for output file below
# 5. Select your object and use arrow keys or frame button 
#    to set your current frame to 1, if you already are at frame 1
#    toggle up and back down a frame back to 1. The script will  
#    create-overwrite your file at each time you go to frame 1
#    use right arrow key to advance through frames till you 
#    reach your desired end frame. A BVH File will be writen to your
#    output path location called ""objectname"Data.bvh"
#
#######################################
import Blender 
#from Blender.BGL import * 
#from Blender.Draw import *
sc = Blender.Scene.getCurrent()
cf = sc.currentFrame()
#######################################
#
totalframes = 100   #Enter Value here
frametime = 0.03333 #Enter Value Here
path = "C:/BVH/"    #Set Your Path Here
#
########################################
# Getting selected object
#
obj = Blender.Object.GetSelected() [0]
#
# Assigning variables and crossconnecting XYZs for C4D 
# 
LX = obj.LocX * 100
LZ = obj.LocY * -100
LY = obj.LocZ * 100
RX = obj.RotZ * 57.2957795
RZ = obj.RotY * 57.2957795
RY = obj.RotX * 57.2957795
#
# printing to the dos window
#
print LX, LY, LZ, RZ, RY, RX
#
# converting values to text string
#
data = repr (LX) +" " +repr (LY) +" " +repr (LZ) +" " +repr (RZ) +" " +repr (RX) +" " +repr (RY)
#
# Writing the header if frame less than 2
# 
if cf < 2: 
   out_file = open(path +obj.name+"Data.bvh", "w")
   out_file.write("HIERARCHY
ROOT Empty
{
	OFFSET 0.00 0.00 0.00 0.00 0.00 0.00
	CHANNELS 6 Xposition Yposition Zposition Zrotation Yrotation Xrotation
}
MOTION
Frames:	"+repr (totalframes)+'
'+"Frame Time:	"+repr (frametime)+'
')
   out_file.write(data+'
') 
   out_file.close 
#
# Appending the data to the file
#
else: 
   out_file = open(path +obj.name+"Data.bvh","a") 
   out_file.write(data+'
') 
   out_file.close
# That's it, its over now.