On 25/10/2016 at 08:31, xxxxxxxx wrote:
Got a little project I'm working on.
Basically I'm trying to make a script that will create a tiled camera for every frame in a user defined range, then save a new file with the frame number as a suffix after setting the tile camera to the scene camera for that frame.
We start with one animated camera
I've identified the following main tasks:
- From the animated camera, create one static camera for each frame of animation in the user defined range.
- Name the cameras with the frame of creation.
- Create tiled camera (from c4d content library) and assign the static camera as reference camera.
- Set number of tiles per axis.
- Enable use tiling.
- Set tiled camera as scene camera.
- Save file as "documentname_TileFrame####.c4d"
The settings on the tiled camera:
The code I've got so far is:
import c4d from c4d import gui import os # Returns a BaseDraw instance bd = doc.GetActiveBaseDraw() def set_render_cam() : """ Sets the currently selected camera to the active render camera """ # Get the selected camera cam = doc.GetActiveObject() # Set the active camera bd.SetSceneCamera(cam) # Re-draws the view c4d.DrawViews() # Adds event c4d.EventAdd() def camera_setup() : # Get int of current frame current_frame = doc.GetTime().GetFrame(doc.GetFps()) # Create null for camera group and set name camgroup = c4d.BaseObject(c4d.Onull) camgroup.InsertBefore(doc.GetFirstObject()) camgroup.SetName('CamGroup Frame' + str(current_frame)) # Create new cam in null and set name newcam = c4d.BaseObject(c4d.Ocamera) doc.InsertObject(newcam, parent=camgroup) newcam.SetName('Frame ' + str(current_frame)) # Gets scene cam data and copies to new cam scene_cam = bd.GetSceneCamera(doc) newcam.SetData(scene_cam.GetData()) newcam.SetMg(scene_cam.GetMln()) # Clones Tiled Camera Base tilecambase = doc.SearchObject("Tiled Camera Base") tilecamclone = tilecambase.GetClone() doc.InsertObject(tilecamclone, parent=camgroup) tilecamclone.SetName('Tiled Cam - Frame ' + str(current_frame)) # Sets 'tiles per axis', 'reference camera' and 'use tiling' tilecamclone[c4d.ID_USERDATA,3] = 5 tilecamclone[c4d.ID_USERDATA,4] = doc.SearchObject('Frame ' + str(current_frame)) tilecamclone[c4d.ID_USERDATA,1] = 1 # Set the scene camera to tiled camera ##bd.SetSceneCamera(tilecamclone) c4d.EventAdd() c4d.DrawViews() def cam_range(start, end) : for f in range(start, end + 1) : doc.SetTime(c4d.BaseTime(f, doc.GetFps())) camera_setup() c4d.DrawViews() c4d.EventAdd() def main() : cam_range(91, 100) if __name__=='__main__': main()
When I run it, it creates the cameras for each frame in the range and names them accordingly.
However, it fails to copy the coordinates (Matrix?) across every frame from the animated camera to each static camera.
Any ideas on how to achieve this?
I've tried the usual googling, but come up dry.
Thanks in advance