Get selected keyframe

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

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

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.

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

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