I'm trying to find a way to export moving camera data (rotation and position) from cinema 4d to a csv file.
I have found a python script on how to get this on ONE single frame. I'll insert the code I found bellow.
This code outputs position (x, y and z) and rotation degrees (x, y and z) on one row in different columns, which is perfect.
My question is how to expand the code to make the script look through each frame in the timeline and not only one frame,
giving each frame it's own row in the csv doc.
My lack of python knowledge hinders me from getting closer to my goals. All help is appreciated!
import c4d
#Welcome to the world of Python
def Walker(obj):
if not obj: return
elif obj.GetDown():
return obj.GetDown()
while obj.GetUp() and not obj.GetNext():
obj = obj.GetUp()
return obj.GetNext()
def main():
file = c4d.storage.SaveDialog(c4d.FILESELECTTYPE_ANYTHING, title='Save csv file as', force_suffix='csv')
csv_file = open(file, 'w')
obj = doc.GetFirstObject()
while obj:
if obj.GetType() == 5103:
name = obj.GetName()
obj_matrix = obj.GetMg()
position = obj_matrix.off
rotation_rad = c4d.utils.MatrixToHPB(obj_matrix,c4d.ROTATIONORDER_XYZGLOBAL)
rotation_deg = c4d.Vector(c4d.utils.Deg(rotation_rad.x), c4d.utils.Deg(rotation_rad.y), c4d.utils.Deg(rotation_rad.z))
line = '%s, %s, %s, %s, %s, %s'%(position.x,
position.y,
position.z,
rotation_deg.x,
rotation_deg.y,
rotation_deg.z)
csv_file.write(line + '\n')
obj = Walker(obj)
csv_file.close()
if __name__=='__main__':
main()