XM Magdalena 3D print, GGeorgy (3D)
LC #42 Pipers Alley

View Full Version : Camera animation export

09-24-2012, 06:57 PM
Hi all

I am completely new to both C4D and the forum, and I am hoping someone could help me in this :)
I need to export the animation data of a camera from C4D to a txt file, i.e. Transformation data of each frame and FOV.
The camera should be with target, not free camera, and the exported txt file should look like this:


with a new line for each frame.
I have this script in maxscript and I am including it here for reference



output_name = getSaveFileName caption:"CameraData File" types:"CameraData (*.txt)|*.txt|All Files (*.*)|*.*|"

if output_name != undefined then

output_file = createfile output_name
local newscale="1.000000"

fn rescaleScene=
case units.SystemType of
#Inches: (newscale= 0.0254)
#Feet: (newscale= 0.3048)
#Miles: (newscale= 1609.344)
#Millimeters: (newscale= 0.001)
#Centimeters: (newscale= 0.01)
#Meters: (newscale= 1)
#Kilometers: (newscale= 1000)
try(setinisetting (objExp.getIniName()) "Geometry" "ObjScale" (newscale as string))catch()


for t = animationrange.start to animationrange.end do


at time t current_pos = $Camera1.pos *newscale
at time t current_target = $Camera1.Target.pos *newscale
at time t theFOV = $Camera1.FOV
at time t thecam_dir=
local posdummy=dummy transform:$Camera1.transform
in coordsys local move posdummy [0,100,0]
local yvec_pos=posdummy.pos
delete posdummy

str = stringStream ""

format "%" theFlags[1][1] to:str
format "#%" theFlags[1][3] to:str
format "#%" -theFlags[1][2] to:str

format "#%" theFlags[2][1] to:str
format "#%" theFlags[2][3] to:str
format "#%" -theFlags[2][2] to:str

format "#%" theFlags[3] to:str

format "#%" -theFlags[4][1] to:str
format "#%" -theFlags[4][3] to:str
format "#%" theFlags[4][2] to:str

mystring = str as string

format "%\n"(mystring) to:output_file


close output_file

edit output_name



If someone can help me in this, or point me to a C4D script that does the same thing or something similar that i can modify to achieve my goal i would very much appreciate it :)

10-09-2012, 03:17 AM
Gentlemen, would you give me a hand with the above script? :)
It will be very much appreciated.

Scott Ayers
10-09-2012, 06:09 PM
Sure. I'll throw you bone.;)
I won't write the entire thing for you. But I'll give you enough of the the basic code framework. So that you should be able to take it from there. And customize it to suit your needs.

This is a python script that runs in the script manager: #This script saves the active camera's positions and FOV to a text file
#The text file is called "myfile.txt" and is located on the Desktop
#Change the code as needed

import c4d
from c4d import storage

def main():

fps = doc.GetFps()
curTime = doc.GetTime() #Store current time so we can get back to it
start = doc.GetLoopMinTime().GetFrame(fps) #Get min loop time, start of writing
end = doc.GetLoopMaxTime().GetFrame(fps) #Get max loop time, end of writing

camera = doc.GetActiveBaseDraw().GetSceneCamera(doc) #Get the active camera
#path = storage.SaveDialog(c4d.FILESELECTTYPE_ANYTHING,'Save Camera Info','txt') #Use this if you want to use a save dialog

filepath = c4d.storage.GeGetC4DPath(c4d.C4D_PATH_DESKTOP) + "/" +"myfile.txt"
camPos = camera.GetRelPos()
FOV = camera[c4d.CAMERAOBJECT_FOV] #The camera's Field of View(horizontal) attribute

file = open(filepath,"w") #Open the file in writable mode

for frame in xrange(start, end+1):
c4d.StatusSetBar(end*(frame-start)/(end-start)) #Animate the staus bar value
doc.SetTime(c4d.BaseTime(frame, fps))

file.write('#CamerPositionX' + '%.2f' % ( camPos.x) + " ")
file.write('#CamerPositionY' + '%.2f' % ( camPos.y) + " ")
file.write('#CamerPositionZ' + '%.2f' % ( camPos.z) + " ")
file.write('#FOV' + '%.2f' % ( FOV) + '\n')

c4d.GeSyncMessage(c4d.EVMSG_TIMECHANGED) #Update timeline

doc.SetTime(curTime) #Set the scrubber back to where it was
c4d.StatusClear() #Re-set the status bar to blank
file.close() #close the file so it can be accessed again

if __name__=='__main__':

Be aware that this forum often screws up the indentations in python code. And also inserts spaces where they shouldn't be. So you might need to fix this code so it doesn't throw errors.
If you have more Python & C4D questions. You'll probably find more coders at www.plugincafe.com
You can learn a lot about the basics just by going through the python forum posts there.


10-10-2012, 04:44 AM
Sure. I'll throw you bone.;)
I won't write the entire thing for you. But I'll give you enough of the the basic code framework. So that you should be able to take it from there. And customize it to suit your needs.

Great, this is what I need, a jump start. I will try the script today.
Thank you Scott :)

10-11-2012, 07:25 AM
This is a python script that runs in the script manager

Hey Scott, I built over your script and got what I want for now. I ran into some other posts of you on some other forums that gave me some good info as well. Thank you :applause:
As a gesture of appreciation for your valuable help, I would like to give you something back in return. Please PM me :)

CGTalk Moderation
10-11-2012, 07:25 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.