I would like to fix an object (for example an Ocube) at different positions depending of the frame number.
Here is my code, inspired by tutorials I've found (https://github.com/PluginCafe/cinema4d_py_sdk_extended)
# Creates the object in memory
obj = c4d.BaseObject(c4d.Ocube)
# Retrieves BaseTime of frame 0, 20
start = 0
end = 20
# Loops through the frames
for frame in range(start, end + 1):
# Move the cube to some position
obj.SetRelPos(c4d.Vector(20+frame*20))
# Creates the track in memory. Defined by it's DescID
trackY = c4d.CTrack(obj, c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_REL_POSITION, c4d.DTYPE_VECTOR, 0),
c4d.DescLevel(c4d.VECTOR_Y, c4d.DTYPE_REAL, 0)))
# Inserts the track
obj.InsertTrackSorted(trackY)
# Inserts the object in document
doc.InsertObject(obj)
# Pushes an update event to Cinema 4D
c4d.EventAdd()
Problem :
This code doesn't fix object in frames. The cube change position at each loop iteration but it's not fixed frame by frame. I guess I need to associated the track to a frame but I haven't found documentation to do this.
What I want
At each loop iteration, I want to reccord a object position as the "Reccord Active Objects" do.
And automatically create a track as it appears on the timeline :
Questions :
- How to link a track to a frame number ?
- Is it a good way to animate the cube frame by frame ?
- Have you a link with examples that could guide me to animate an object frame by frame in python ?
Thanks