0

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.

Reccord button

And automatically create a track as it appears on the timeline :

Track on 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

Corentin
  • 325
  • 5
  • 21

1 Answers1

1

I was missing something when I read the documentation but I finally found an answer that fit my need at this link :

https://github.com/PluginCafe/cinema4d_py_sdk_extended/blob/master/scripts/04_3d_concepts/scene_elements/animation/ctrack_create_keys_r13.py

Corentin
  • 325
  • 5
  • 21