Featured post

new redirect for blender.org bpy docs.

http://www.blender.org/api/blender_python_api_current/ As of 10/11 november 2015 we can now link to the current api docs and not be worr...

July 21, 2011

scripted keyframing of hide / hide render setting on object

###### place at t = T_START-1 a keyframe with hide set to True
current_frame = T_START-1
bpy.context.active_object.hide = True
bpy.context.active_object.keyframe_insert(  data_path="hide", 
###### place at T_START a keyframe with hide set to False
current_frame = T_START
bpy.context.active_object.hide = False
bpy.context.active_object.keyframe_insert(  data_path="hide", 
It's handy to make keyframes first as experiment for lateron when you try to script something, if you can't get the basics going manually don't expect to be able to script it without understanding the sequence of operations required.

If you have a property that you want to keyframe, then you will need to know the data_path. In the code example below i choose to keyframe the 'hide' property. If you are unsure about the string name needed for data_path, then rightclick the property/icon and select "copy data_path". Then paste that into ( console / TextEditor / your code ) to see the path.

if you need to remove all your animation data use action-data-how-to-purge.html

you might set up a hide animation like this
( side note: data_path='hide' hides from view, not from render.. that's data_path='hide_render' ).

# For instance you first define T_START, T_END and LAST_FRAME
# T_START and T_END as the first and last frames that the object will be visible in.
# Having an additional keyframe on either side of those frames allows you to play
# the sequence backwards without messing up the hide duration.  
# "hide" ( hides from view ) use "hide_render" to make it apply to render.
    time_and_state_settings = ( (0, True), 
                                (T_START-1, True),
                                (T_START, False),
                                (T_END, False),
                                (T_END+1, True),
                                (LAST_FRAME, True))

    for time_val in time_and_state_settings:    
        current_frame = time_val[0]
        bpy.context.active_object.hide = time_val[1]
        bpy.context.active_object.keyframe_insert(  data_path="hide",