Camera animation export

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 09 September 2012   #1
Camera animation export

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:

xSource#ySource#zSource#xTarget#yTarget#zTarget#xU p#yUp#zUp#FOV

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()
)

rescaleScene()

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
camup_pos=normalize($Camera1.pos-yvec_pos)
)


theFlags=#(current_pos,current_target,theFOV,theca m_dir)
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
 
Old 10 October 2012   #2
Gentlemen, would you give me a hand with the above script?
It will be very much appreciated.
 
Old 10 October 2012   #3
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,'Sa  ve 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))
		c4d.DrawViews(c4d.DRAWFLAGS_ONLY_ACTIVE_VIEW|c4d.D  RAWFLAGS_NO_THREAD|c4d.DRAWFLAGS_NO_REDUCTION|c4d.  DRAWFLAGS_STATICBREAK)
				
		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.EventAdd(c4d.EVENT_ANIMATE)
	c4d.StatusClear()								 #Re-set the status bar to blank
	file.close()									  #close the file so it can be accessed again

if __name__=='__main__':
	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.

-ScottA
__________________
My Gallery
 
Old 10 October 2012   #4
Originally Posted by Scott Ayers: 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
 
Old 10 October 2012   #5
Thumbs up

Originally Posted by Scott Ayers: This is a python script that runs in the script manager
-ScottA


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
As a gesture of appreciation for your valuable help, I would like to give you something back in return. Please PM me
 
Old 10 October 2012   #6
Thread automatically closed

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.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 10:54 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.