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
Exclamation Multi-Threaded Camera Feed issue Khajababa69 0 319 May-05-2024, 09:44 PM
Last Post: Khajababa69
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 1,228 Dec-15-2022, 04:32 PM
Last Post: Larz60+
  Get image from PI camera and analyze it korenron 0 1,253 Apr-28-2022, 06:49 AM
Last Post: korenron
  Modify values in XML file by data from text file (without parsing) Paqqno 2 1,842 Apr-13-2022, 06:02 AM
Last Post: Paqqno
  Converted Pipe Delimited text file to CSV file atomxkai 4 7,259 Feb-11-2022, 12:38 AM
Last Post: atomxkai
  Create RTSP stream from camera? korenron 1 3,428 Jan-04-2022, 10:38 AM
Last Post: Larz60+
  How to get OpenCV to display entire camera frame? George713 1 3,375 Aug-12-2021, 02:45 AM
Last Post: Pedroski55
  [split] How to convert the CSV text file into a txt file Pinto94 5 3,523 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,580 Nov-16-2020, 07:56 AM
Last Post: Gribouillis
  Wifi Camera Connection MeenAg 2 3,228 Oct-02-2020, 06:35 PM
Last Post: MeenAg

Forum Jump:

User Panel Messages

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