MAXON CINEMA 4D: Cinema 4D Forum Adobe After Effects Forum

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

COW Forums : Maxon Cinema 4D

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
Miguel de Mendoza
Add keys to scene object by python/coffe from a csv/xml file.
on Mar 31, 2016 at 8:26:25 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.

Return to posts index

Miguel de Mendoza
Re: Add keys to scene object by python/coffe from a csv/xml file.
on Apr 4, 2016 at 12:31:29 am
Last Edited By Miguel de Mendoza on Apr 4, 2016 at 12:40:30 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):
# 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

Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 All Rights Reserved