Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Easier Way to Offset an Animation of an Object?

    Cinema 4D SDK
    python r25 windows r21
    2
    4
    976
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B
      bentraje
      last edited by bentraje

      Hi,
      Is there an easy way to offset an animation of an object?
      For example, I have a position.x track keyframe to from 5 to 10.
      I just want to offset it by 2 frames through python.
      Is there a one liner to do it? c4d.MoveTrack(frame=2) or something?

      Haven't tried it but there is CCurve.MoveKey or something.
      So it woud be like. Get Track. Get Curve. Get Key shenanigan. Loop through those keys. Loop through those curves etc.

      I just really want to offset it Track.
      Is there an easier of doing that?

      P.S. And I think there's no sample code on how to do it in the forum or in the documentation.

      1 Reply Last reply Reply Quote 0
      • B
        bentraje
        last edited by

        Okay. Manage it figure moving it without using the MoveKey. Still verbose though 😞

        import c4d
        
        def main():
            obj = doc.GetActiveObject()
            desc_x = c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_POSITION, c4d.DTYPE_VECTOR, 0),
                            c4d.DescLevel(c4d.VECTOR_X, c4d.DTYPE_REAL, 0))
            track = obj.FindCTrack(desc_x)
            curve = track.GetCurve()
           
           
            key_count = curve.GetKeyCount()    
            fps = 24
            offset_frame = 2
            
            for index, value in enumerate(range(key_count)):
                key = curve.GetKey(index)
                time = key.GetTime()
                frame =  (time.GetFrame(fps))
                new_frame = frame + offset_frame
                new_time = c4d.BaseTime(new_frame/fps)
                
                key.SetTime(curve, new_time)
            
            c4d.EventAdd()
                
        main()
        
        ferdinandF 1 Reply Last reply Reply Quote 0
        • ferdinandF
          ferdinand @bentraje
          last edited by ferdinand

          Hey @bentraje,

          Thank you for reaching out to us. That is the only way to do it as far as I know. APIs tend to require much more verboseness than user interfaces. And the Python Cinema 4D API is there quite harmless, try C++ πŸ˜‰

          a055e4dc-2b0c-41c9-81d0-4a6c5f031cfa-image.png

          Cheers,
          Ferdinand

          MAXON SDK Specialist
          developers.maxon.net

          1 Reply Last reply Reply Quote 1
          • B
            bentraje
            last edited by

            @ferdinand

            yea python is much more forgiving than C++. i was just wondering if there was an already existing API for such task. πŸ‘

            1 Reply Last reply Reply Quote 0
            • First post
              Last post