Python Forum
Camera animation to Text file (CINEMA 4D)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Camera animation to Text file (CINEMA 4D)
#1
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()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 1,105 Dec-15-2022, 04:32 PM
Last Post: Larz60+
  Get image from PI camera and analyze it korenron 0 1,149 Apr-28-2022, 06:49 AM
Last Post: korenron
  Modify values in XML file by data from text file (without parsing) Paqqno 2 1,641 Apr-13-2022, 06:02 AM
Last Post: Paqqno
  Converted Pipe Delimited text file to CSV file atomxkai 4 6,938 Feb-11-2022, 12:38 AM
Last Post: atomxkai
  Create RTSP stream from camera? korenron 1 3,240 Jan-04-2022, 10:38 AM
Last Post: Larz60+
  How to get OpenCV to display entire camera frame? George713 1 3,247 Aug-12-2021, 02:45 AM
Last Post: Pedroski55
  [split] How to convert the CSV text file into a txt file Pinto94 5 3,296 Dec-23-2020, 08:04 AM
Last Post: ndc85430
  Saving text file with a click: valueerror i/o operation on closed file vizier87 5 4,380 Nov-16-2020, 07:56 AM
Last Post: Gribouillis
  Wifi Camera Connection MeenAg 2 3,077 Oct-02-2020, 06:35 PM
Last Post: MeenAg
  saving data from text file to CSV file in python having delimiter as space K11 1 2,386 Sep-11-2020, 06:28 AM
Last Post: bowlofred

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020