I'm creating a stop motion animation that requires to Insert Keyframes of visibility. I was attempting to work out a script to make this process faster for me, but being new to python this has evaded me. Any help would be appreciated.

My work flow goes as:

  1. Select object (with mouse)
  2. Insert key frame on both viewport and rendering visibility
  3. Hide Viewport bpy.context.object.hide = True
  4. Hide Rendering bpy.context.object.hide_render = True
  5. Move Next Frame
  6. Un-hide Viewport bpy.context.object.hide = False
  7. Un-hide Rendering bpy.context.object.hide_render = False
  8. Insert key frame on both viewport and rendering visibility

Update based on accepted answer

Other then the following comments, I can't find any other issues.

  • If you run the script multiple times It will continue to add buttons.
  • Also I agree with you on Just inserting a keyframe instead of hiding and adding a keyframe.
  • Is there any way to apply the Hide keyframes to multiple items at once? It seems only the last selected item receives the keyframe change.

enter image description here

Also once again a huge thanks, here is a frame of how it turned out! Multiple Instances can be ran if script is ran more then once


1 Answer 1


This adds a button to the 3D View tool panel, Animation tab:

import bpy

class OBJECT_keyframe_insert_hide(bpy.types.Operator):
    bl_idname = "object.keyframe_insert_hide"
    bl_label = "(Un)hide"
    bl_options = {'REGISTER', 'UNDO'}

    hide = bpy.props.BoolProperty(name="Hide")

    def poll(cls, context):
        return context.object is not None

    def execute(self, context):
        ob = context.object
        ob.hide = self.hide
        ob.hide_render = self.hide
        return {'FINISHED'}

def draw_func(self, context):
    layout = self.layout
    hidden = context.object.hide

    layout.label("Stop motion:")
    layout.operator(OBJECT_keyframe_insert_hide.bl_idname, text="Unhide" if hidden else "Hide", icon='KEY_HLT').hide = not hidden

def register():

def unregister():

if __name__ == "__main__":

It hides or unhides the active object and keyframes the .hide / .hide_render properties.

Insert Keyframes for hide and hide_viewport (toggle)

  • $\begingroup$ This is perfect for what I am looking for. Thank you so much for a quick and thorough answer. $\endgroup$ Commented Sep 24, 2014 at 14:43
  • $\begingroup$ You're welcome. I would like to hear any issues in usability if there are any. Maybe it would be nicer if it didn't hide the object on the initial button press when there are no keyframes yet, but inserted a keyframe only? $\endgroup$
    – CodeManX
    Commented Sep 24, 2014 at 19:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .