Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Maxon Cinema 4D Add keys to scene object by python/coffe from a csv/xml file.

  • Add keys to scene object by python/coffe from a csv/xml file.

    Posted by Miguel De mendoza on March 31, 2016 at 8:26 am

    Hi, I’m working on a project with about 13 cameras. I rendered all the cameras with software render to edit a preview before I make the final render. I have edited the full video and my idea is to write a script for after effects to generate a csv/xml file that stores each clip piece name and their corresponding in and out points, then load this file in c4d to to set all the corresponding keyframes on a scene object. I want to know if is posible to read csv/xml file and set those keyframes with python or coffe and how can I access to scene object and his properties, or if someone can give me a starting spot to achieve it.
    Thanks!

    Miguel De mendoza replied 10 years, 1 month ago 1 Member · 1 Reply
  • 1 Reply
  • Miguel De mendoza

    April 4, 2016 at 12:31 am

    After some depth search I found the way to keyframe the stage object, down is the code snippet if somone needs something similar. The samples parameter is simply a list of dict values to reference the camera name and his inpoint:

    def setKeysFromCameraSamples(samples):
    # DESCRIPTION:
    # Set the keyframes from the samples object to the stage object
    if samples is None or len(samples) is 0:
    return False

    stageList = doc.GetActiveObjectsFilter(True, c4d.NOTOK, 5136) # Find selcted stage objects
    if len(stageList) is 0: # Check if there are stage objects selected
    c4d.gui.MessageDialog('Select a stage object') # If not, return
    return False
    elif len(stageList) > 1: # Check if there are more than one object selected
    c4d.gui.MessageDialog('Select only one stage object') # If there are, return
    return False

    stage = stageList[0] # Select the first scene object
    dCamera = c4d.DescID(c4d.STAGEOBJECT_CLINK) # Reference to a cameraLink property
    cameraTrack = stage.FindCTrack(dCamera) # Reference the camera link track

    if not cameraTrack: # If there is no camera track, create it
    cameraTrack = c4d.CTrack(stage, c4d.STAGEOBJECT_CLINK) # Create a track
    stage.InsertTrackSorted(cameraTrack) # Insert the track

    fps = doc.GetFps() # Get the document framerate
    curve = cameraTrack.GetCurve() # Reference the track curve

    for curSample in samples: # Iterate through sample list
    frame = curSample['INPOINT'] # Get the inpoint of the sample
    cameraName = curSample['CAMERA'] # Get the sample camera
    curCamera = doc.SearchObject(cameraName) # Find that camera in the project
    frameTime = c4d.BaseTime(frame, fps) # Parse the key frame to c4d time
    keyDict = curve.AddKey(frameTime) # Add a new key to the curve
    keyDict['key'].SetGeData(curve, camera) # Link the current camera to the key
    c4d.eventAdd() # Refresh

    Return True

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy