Animatic Preview script (show only keyframes)

Here’s a piece of python that will preview the currently selected object(s)’ keyframes like an animatic. That is, without interpolation, but keeping timing intact. This little function is part of a larger space handler script I wrote so I could block out poses without the distraction of interpolation issues. If anybody’s interested, I can post the whole script, which includes an “animatic render” function too.

Also, if anybody knows how to capture a keypress whilst running python (I want to be able to ESC out of the animation), do tell!


# this previews an animation in "animatic" style, that is, without interpolation.
# Keyframes that are honored are the keyframes in the selected objects.

import Blender as B
import Blender.Armature as Armature

def GatherKeyframes(selected, Min=-1, Max = -1):
    """
    Gather all keyframes inside the objects passed & return a sorted list of frame numbers
    """
    keyframe_frames = []
    for s in  selected:
        ipo = s.getIpo()
        if ipo:
            for curve in ipo.curves:
                for p in curve.bezierPoints:
                    frame = int(round(p.pt[0])) # x value, which is keyframe
                    if not frame in keyframe_frames:
                        keyframe_frames.append(frame)
        if s.getType() == 'Armature':
            # get its keyframes, too
            action = s.getAction()
            if action:
                keyframe_frames.extend(action.getFrameNumbers())
    result = []
    current = None
    for x in sorted(keyframe_frames):
        if Min >=0 and x < Min:
            continue
        if Max >=0 and x > Max:
            continue

        #remove dupes:
        if current != x:
            current = x
            result.append(x)
        
    return sorted(result)

def AnimaticPreview():
    """
    Play a preview like an animatic, without interpolation by jumping from keyframe to keyframe,
    keeping timing intact. Honor the keyframe of the selected object(s).
    """
    
    
    # get keyframes of the selected objects
    # or all in scene if no selection
    selected = B.Object.GetSelected()
    if len(selected) == 0:
        selected = B.Object.Get()
        
    keyframe_frames = []
    
    # get user settings from render
    context = B.Scene.GetCurrent().getRenderingContext()
    FPS = float(context.fps)
    start = context.sFrame
    end = context.eFrame
    
    keyframe_frames = GatherKeyframes(selected, start, end)
    
    # add start & end frame (for playback purposes)
    if not start in keyframe_frames:
        keyframe_frames = [start] + keyframe_frames
    if not end in keyframe_frames:
        keyframe_frames.append(end)
    
    
    # play it
    
    frameBackup = B.Get('curframe') # to restore later
    
    startTime = B.sys.time()
    t = 0.0
    
    for f in keyframe_frames:
        nextTime = f/FPS
        t = B.sys.time() - startTime
        # CHECK HERE FOR ESC KEY
        if nextTime > t:
            B.sys.sleep((nextTime - t) * 1000.0);
            
        B.Set('curframe', int(f))
        B.Redraw()
        print nextTime, B.sys.time() - startTime
    
    
    #restore working frame
    B.Set('curframe', frameBackup)
    B.Redraw()

# do it:
AnimaticPreview()

I have not worked with space handlers, but here is the code I use for a standard GUI exit.


 elif evt == EXIT:
  print "Exiting..."
  print "<<"
  Draw.Exit()

Does a space handler generate events you can detect?

Blinkozo the [Animatic](: http://www.showboatentertainment.com/animatics-production-company.html)preview script you had posted is good well i will go through it and let you further info

This script i have to run it from inside blender by pasting it in text editor ?