Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python 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

    Get selected keyframe

    Scheduled Pinned Locked Moved PYTHON Development
    6 Posts 0 Posters 564 Views
    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.
    • H Offline
      Helper
      last edited by

      On 11/01/2017 at 11:48, xxxxxxxx wrote:

      Hi
      If i have one or more keyframes selected in the timeline, how can i access them in python? I'm trying to figure out how to change the angle of the seleceted keyframes handles. But I can't even figure out how to get the user-selected keyframe 🙂

      -b

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        On 11/01/2017 at 11:59, xxxxxxxx wrote:

        Good food for brain can be found here
        https://developers.maxon.net/forum/topic/5517/5536_selected-keys-move-keys
        http://www.cineversity.com/wiki/Python%3A_Keyframe_Selections/

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          On 11/01/2017 at 12:21, xxxxxxxx wrote:

          Thanks. I've seen those.
          The first links solution is sort of what i'm looking for but it only works if you have an object selected first. I need to run my code by only selecting one or more keyframe(s) in the timeline. If possible.
          The second link is for listing the selected objects "Keyframe Selections" This is a way to set what parameters are animated when recoding new keyframes.

          -b

          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

            On 12/01/2017 at 07:40, xxxxxxxx wrote:

            Hi,

            unfortunately I'm not aware of a shortcut to directly access the selected keyframes. But Niklas' MoveSelectedKeys function works nicely regardless of the selection state of an object. So you can iterate the object (or materials, shaders,...) hierarchy and use roughly Niklas' code to find the selected keyframes.

            I will forward the idea for a convenience function to development.

            1 Reply Last reply Reply Quote 0
            • H Offline
              Helper
              last edited by

              On 12/01/2017 at 09:46, xxxxxxxx wrote:

              Wonderful. I'm using Niklas's code for the time being.
              But it would be very handy having such functions available.

              -b

              1 Reply Last reply Reply Quote 0
              • H Offline
                Helper
                last edited by

                On 13/01/2017 at 16:18, xxxxxxxx wrote:

                Holy mackerel, that's an old post @gr4ph0s linked. Note that there's a bug in MoveSelectedKeys() if
                you pass a value for timeln not in the range [1..4].

                def MoveSelectedKeys(op,offset,timeln = 1) :    # offset in frames
                    import c4d
                  
                    if (not op) or (not offset) : return False
                  
                    if timeln == 1: timeln = c4d.NBIT_TL1_SELECT
                    elif timeln == 2: timeln = c4d.NBIT_TL2_SELECT
                    elif timeln == 3: timeln = c4d.NBIT_TL3_SELECT
                    elif timeln == 4: timeln = c4d.NBIT_TL4_SELECT
                    else:
                        import math
                        timeln = math.fmod(timeln,4)
                        MoveSelectedKeys(op,offset,timeln)
                        **return  # <<< missing**
                  
                    doc = op.GetDocument()
                  
                    track = op.GetFirstCTrack()
                    if not track: return False
                  
                    fps = float(doc.GetFps())
                  
                    while track:
                        curve = track.GetCurve()
                        cnt = curve.GetKeyCount()
                        for i in xrange(cnt) :
                            key = curve.GetKey(i)
                            if key.GetNBit(int(timeln)) == True:
                                tme = key.GetTime()
                                key.SetTime(curve,c4d.BaseTime(offset/fps+tme.Get()))
                        track = track.GetNext()
                    c4d.EventAdd(c4d.MSG_UPDATE)
                  
                    return True
                
                1 Reply Last reply Reply Quote 0
                • First post
                  Last post